4,305 Posted Topics
Here we experiment with a gauge or progress bar made from a label displaying a variable number of spaces in color. In this example, we use from 0 to 100 spaces. This label based gauge allows you to choose many different colors, and you can even change the color as … | |
Re: I changed my New Year's Resolution to not making any New Year's Resolution in the future. :) | |
Re: You could store it as a list of (x, y) or (x, y, z) tuples. I think [B]richieking[/B] already gave you the hint. | |
Re: I fell in love with Python the moment I started using it to solve scientific problems. That was about 7 years ago. Before that I used C and then Pascal/Delphi. | |
Re: Might be better to find a virus that gets rid of all mosquitoes. Who needs those blood sucking beasts anyway? :) | |
Re: Here is one example I have: [QUOTE]Quit will quit the tcl interpreter of Tkinter! If IDLE is used, then quit will freeze it, since IDLE uses Tkinter too! Replace quit with destroy, destroy is used to destroy a particular window in a multiwindow program.[/QUOTE] | |
Re: The Spanish Flu after WW1 was mostly a bird flu and killed about 50 million people worldwide. Of course nobody in those days even knew what a virus was. In this modern age influenza kills about 36,000 people in the USA every year. Of course mostly the elderly and very … | |
Does anybody have a tested function in C or C++ that sends text to the printer in a Windows Console Application? I would be very appreciative! It would be nice, if I could specify the font. Yes, I can google! | |
Re: With older versions of Python you might have to use ... [code]""" file_1.txt--> 99 root S 5176 95 41.2 8.3 snmpd file_2.txt--> 99 root S 5176 95 1.0 8.3 snmpd """ from __future__ import with_statement with open('file_1.txt') as file_1: with open('file_2.txt') as file_2: f1 = [float(item.split()[5]) for item in file_1] … | |
Re: [COLOR="Red"]after pylab.show() I don't get the >>> in IDLE! The program stalls on that last pylab.show() statement.[/COLOR] For heaven sake don't run the code from the Python shell! Run it from the editor! The python shell is used for testing very short Python code concepts, mostly one-liners! | |
Re: If you want to do that with a while loop, you need an updated counter and an exit condition. | |
| |
Re: Something like this could do it ... [code]listA = [1, 5, 3, 4] # index to be excluded index = 1 mx = 0 for ix, n in enumerate(listA): if n > mx and ix != index: mx = n print(mx) [/code] | |
Re: Something like this may give you a hint ... [code]def extract_number(data_str): """ extract the numeric value from a string (the string should contain only one numeric value) return the number or None """ s = "" for c in data_str: if c in '1234567890.-': s += c if s: # … | |
Re: You could take a look at: [url]http://www.riverbankcomputing.com/software/pyqt/download[/url] Also check if the Eric IDE is available in your repository. It is written in Python and PyQT and should install PyQT for you. [url]http://eric-ide.python-projects.org/[/url] | |
Re: Python does "duck typing", look at this example ... [code]def adder(d): d = d + d print d x = 1 adder(x) # 2 x = 1.5 adder(x) # 3.0 x = 'bon' adder(x) # bonbon [/code] | |
Re: You could change your last lines to something like this ... [code]print '-'*10 print "lines different in text 2 from text 1:" difference21 = "" for line in result: if line[0] == '+': print line difference21 += line print '-'*10 print "lines different in text 4 from text 3:" difference43 … | |
Re: [QUOTE=Blackberryy;1409211]Cheers for your help guys. Not sure what Tkinter is as i am using the graphics module anybody have any help using the graphics module.[/QUOTE] John Zelle, Ph.D. teaches Python at Wartburg College He is the author of graphics.py used by a number of schools instead of Tkinter Get the … | |
Re: turtle.circle(radius, extent=None, steps=None) extent is an angle, 360 by default, less than 360 for an arc | |
Re: Take a look at: [url]http://www.daniweb.com/code/snippet335783.html[/url] | |
This little code snippet shows you how you save a wxPython canvas drawing to a standard image file. | |
Re: Pelles C is free and comes with support for Pocket PC and Smartphones. It has a great IDE and helpfile! Download it from: [url]http://smorgasbordet.com/pellesc/index.htm[/url] | |
Re: Take the Earth's population and divide it by 5.344 | |
Re: Take a look at: [url]http://sourceforge.net/projects/pymilter/[/url] very sophisticated approach: [url]http://www.ailab.si/orange/[/url] | |
Re: I am showing this only as a basic example of a recursive function ... [code]# a typical example of a recursive function # there is a limit to recursions in Python # sys.getrecursionlimit() --> usually 1000 # can be changed with # sys.setrecursionlimit(new_limit) def palindrome_recursive(s): # slicing gets the first … | |
Re: Python has a module ConfigParser that makes writing and reading configuration files easier. Look in your Python documentation, there are actual examples there. | |
Re: My fatherly advice, do not name a variable [COLOR="Red"]str[/COLOR] since [COLOR="Red"]str[/COLOR] is also a built-in Python function name. This would get you into trouble if you ever want to use the str function later in your code. | |
Re: The Tkinter GUI toolkit that installs with just about every Python version, has some power under the hood even for console applications. See: [url]http://www.daniweb.com/forums/post1288813.html#post1288813[/url] | |
Re: Just a few common Python functions will do ... [code]# find the index of the largest item in a list # index starts at zero a = [77, 123, 18] a_max = max(a) ix_max = a.index(a_max) print(a) # [77, 123, 18] print(a_max) # 123 print(ix_max) # 1 [/code] | |
Re: Here is an example using PIL ... [code]# use the Python Image Library (PIL) to load and flip an image # convert the two PIL images to Tkinter images and display # tested with Python26 by vegaseat import Tkinter as tk from PIL import Image, ImageTk root = tk.Tk() cv … | |
Re: Download the BCX system from: [url]http://www.rjpcomputing.com/programming/bcx/devsuite.html[/url] It's free, creates C or C++ code you can look at and learn from. Super help file and lots of GUI samples. Look at BCX as a preprocessor. I use it all the time, a great learning tool. | |
Re: C (or its OOP cousin C++) is a compiled language and will be faster than an interpreted language like Python. | |
Re: One way ... [code]text = 'This is a line of text' # notice the added spaces new_text = text.replace(' is ', ' is not ') print(text) # This is a line of text print(new_text) # This is not a line of text [/code] | |
Re: With minor breaks I have done up to 18 hours of coding in a day's time. After that, things get even more goofy than normal. | |
Re: [QUOTE=novice20;1426811]can anyone suggest a simple method to define an enum in python. as some examples floating on net, i used class Animal: DOG=1 CAT=2 print Animal.DOG but it doesn't seem to be working...[/QUOTE] This works ... [code]class Animal: DOG = 1 CAT = 2 print Animal.DOG # 1 [/code] | |
Re: 2010 resolution --> drop your weight by 10 pounds 2011 resolution --> drop your weight by 5 pounds | |
Re: It might be simpler to draw a Koch fractal using the module turtle that comes with your Python installation ... [code]import turtle as tu def Koch(length): """draw a Koch fractal curve recursively""" if length <= 2 : tu.fd(length) return Koch(length/3) tu.lt(60) Koch(length/3) tu.rt(120) Koch(length/3) tu.lt(60) Koch(length/3) tu.speed(0) length = 300.0 … | |
Re: What is missing here is an example of a text entry followed by a numeric entry. I tried to combine the code presented and should the text exceed its length of 19 and have numbers at the end, ouch! | |
Re: The keys in a Python dictionary are in hash order for fast look-up. You can not maintain alphanumeric order unless you use an OrderedDict object, new in Python27 and higher. | |
Re: Create your random numbers inside the loop, something like this ... [code]# generate random number a certain number of times import random # now print different number 10 times for count in range(1,11): # create random numbers d1= random.randint(1,10) d2= random.randint(1,10) print (d1,d2) [/code] | |
Re: [QUOTE=pi_lord12;1420529]Hey, I'm new to Python and wondering about the following bit of code. It tells me that the module random has no attribute randint. I've looked at the documentation and such and I think I'm doing it correctly, but obviously something's wrong. Any ideas? Thanks! [code] import random int1=random.randint(1, 6) … | |
Re: I am running Python 25, 26, 27 and 31 in my Windows7 machine. The trick is to use an IDE like Editra that allows you to specify which Python version to use. | |
Re: If you want to do a selection sort without any for/while, you have to do a recursive function. List comprehension does contain a for loop. [QUOTE]Hopefully helpful hint: A selection sort of a list of numbers is pretty simple. You start with two lists, let's call the original unsorted list … | |
Re: Just to interject the lighter side of the nuptials into this sometimes sober discussion ... [QUOTE] By all Means... MARRY! I recently read that love is entirely a matter of chemistry. That must be why my wife treats me like toxic waste. - David Bissonette When a man steals your … | |
Re: An oldy but goody (includes Tkinter): [url]http://bembry.org/technology/python/index.php[/url] Tkinter reference: [url]http://infohost.nmt.edu/tcc/help/pubs/tkinter/tkinter.pdf[/url] Another tutorial source (uses graphics.py, a simplified wrapper for Tkinter): [url]http://webpages.cs.luc.edu/~anh/python/hands-on/index26.html[/url] This online book does not touch graphics, but is rather thorough with Python: [url]http://learnpythonthehardway.org/static/LearnPythonTheHardWay.pdf[/url] Swaroop C.H. has rewritten his excellent beginning Python tutorial for Python3 (Python2 version is still … | |
Re: Show us the code you have and the error message, so we can help you. | |
Re: I would use ... [code] # the next 2 items have to be numbers not strings increase_rate = float(name_DOB_salary[4]) initial_money = float(name_DOB_salary[3]) final_money = initial_money + initial_money*increase_rate [/code]... and then multiply increase_rate by 100 to get percent | |
Re: What a lively thread!!! I have been accused of using lame old Turbo C code in the past by our friend Narue, and heeded her salutary advice. I have to admit that I enjoy her comments a lot, and of course the always impeccable English. Please take it easy on … |
The End.