988 Posted Topics
Re: Rather then MySQL you can use SQLite, sqlite3 is built into Python version 2.5 or you can download pysqlite2 for older versions. Here is an example to create a database file: [php]# create a SQL database file # pySQLite homepage (for Python24): http://initd.org/tracker/pysqlite # tested with Python25 (has sqlite3 builtin) … | |
Re: You need to learn to experiment a little with the code, its fun! [php]# let user resize the Tkinter window, but do not move widgets from Tkinter import * root = Tk() b1 = Button(root, text='Button 1') # tells the widget not to expand into the packing cell # and … | |
Re: Here is away to take care of chemical prefixes like 'o-', 'm-' and 'p-' when sorting. Just a little commonly used trick you can also use when sorting by your table columns: [php]# table of chemicals in stockroom as list of lists # order --> stock number, chemical name, quantity … | |
Re: Can you give us your present code, just to see how this may fit in. | |
Re: There are a number of GUI toolkits for Python, but they are all Python wrappers for other languages. Tkinter is based on tcl, wxPython is based on wxWindows (works on Unix and Windows) written in C++, there is pygtk based on the ever so popular GTK, even pygame can be … | |
Re: Avoiding the endless begin/end or curly braces, and also the end of line semicolons makes code simpler to read and understand. When you use an editor made for Python, indentations become easy to follow. You absolutley have to avoid mixing spaces with tabs in your indents. That's the main reason … | |
Re: Looks like yo want to open a file called "50" even though the list is all integers. | |
Re: You need to start a new thread with the proper title and give us the two files, so we can troubleshoot your program! | |
Re: You can use eval() to turn a string into an object. | |
Re: So that is where that went to! I thought I saw that for a moment in the stickies. | |
Re: Check out the Py2Exe sticky at: [url]http://forums.devshed.com/python-programming-11/py2exe-step-by-step-guide-209432.html[/url] | |
Re: You can use the Python Image Library module to create thumbnails of images, see: [url]http://www.daniweb.com/code/snippet209.html[/url] | |
Re: Interesting project, I will play with it! Just curious, is this a computer science course? Hard to digest, since most CS departments are bastions of conservative stuff like C++ and Java. Engineering and Science departments luckily have been more pragmatic and open to using Python. | |
Re: Solving a project's problems is really a good way to learn Python. You did well! | |
Re: [INLINECODE]C:\Documents and Settings\RockStar\Desktop\Python\drpython-161\Cards_gifC2.gif [/INLINECODE] looks like your image directory is [INLINECODE]C:\Documents and Settings\RockStar\Desktop\Python\drpython-161\[/INLINECODE] and your image file name is [INLINECODE]Cards_gifC2.gif[/INLINECODE]. You wnat to make this [INLINECODE]C:\Documents and Settings\RockStar\Desktop\Python\drpython-161\Cards_gif\[/INLINECODE] and then the image name will be [INLINECODE]C2.gif[/INLINECODE] | |
Re: You were very close: [php]# search lists mammal_list = ['cat', 'dog', 'ape', 'cow'] bird_list = ['chicken', 'crow', 'quail', 'finch'] animal = raw_input("Enter an animal: ") if animal in mammal_list: print "This animal is a mammal" elif animal in bird_list: print "This animal is a bird" else: print "This animal is … | |
Re: You are lucky getting a hold of Robin, the expert with wxPython. Did he ask you to buy his book on wxPython? | |
Re: This is the Python forum, I think you have to post this in the Java forum! | |
Re: You use something like shutil.copy(source_file, destination_file). You can't use the items in listbox2 since that's only the filename, so you have to use the items in the companion fullpath_list. The source_file is made up from the tuple's dirname and filename components. The destination_file is made up from the destination directory … | |
Re: Hi there danizzil14, I am giving you two examples of a simple Tkinter 'Hello World' code. The first one is without the use of class: [code=python]# Tkinter programming without a class from Tkinter import * def say_hi(): # function for hi_button action # show new text on the label hi_label.config(text="Hi … | |
Re: Scripting languages: If you are familiar with C/C++ use Python. If you are familiar with Java use Jython. If you are familiar with Csharp use Lsharp (LispSharp). | |
Re: I go for a grilled panini sandwich with chicken, spinach and mushrooms. | |
Re: Must be your first attempt at ELIZA type AI. The function friends() is called, but does not exist. What is it supposed to do? ![]() | |
Re: Any program with extension .pyw is considered a windows program, not a console program! | |
Re: [QUOTE=macca1111;267896]I tried your suggestionL [PHP] for item in names: ch = item # main code if ch[1:6] == [1,0,0,0,0]: c,m,b,e,t = bbf(c,m,b,e,t) c=+1 elif ch[2:6] == [0,0,0,1]: c,m,b,e,f = bbf(c,m,b,e,f)[/PHP] but doesn't seem to add the 1 to the end totals[/QUOTE] A little error here use [INLINECODE]c = c + … | |
Re: This is a perfect application for a class! I took the Python snippet at: [url]http://www.daniweb.com/code/snippet390.html[/url] and modified it slightly for the solvent database application: [php]# example of a small solvent database using a list of class instances import operator # for attrgetter() class Solvent(object): """a structure class for solvents, self … | |
Re: [QUOTE=sneekula;269882]Thank you! I am still trying to digest the one liners, particularly: [code][COLOR=#0000bb]x_reversed [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000bb]int[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000bb]str[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000bb]x[/COLOR][COLOR=#007700])[::-[/COLOR][COLOR=#0000bb]1[/COLOR][COLOR=#007700]]) [/COLOR] [/code]Can anybody break that down for me so I can see the flow?[/QUOTE] [php]x = 12345 x_string = str(x) # "12345" x_reversedstring = x_string[::-1] # "54321" x_reversed = int(x_reversedstring) # 54321 [/php] | |
Re: Import is only for Python files that are written as modules. If you want to execute an external Python program use [INLINECODE]execfile("myfile.py") [/INLINECODE]or [INLINECODE]execfile("myfile.pyw")[/INLINECODE]. In your program the line [INLINECODE]if denaystart == "denay" or "denay wiles":[/INLINECODE]is wrong. It should be [INLINECODE] if denaystart == "denay" or denaystart == "denay wiles":[/INLINECODE] … ![]() | |
Re: Why do you want to keep two lists, a card has both a rank and a suit, they belong together to make the card. If you just shuffle the rank list, then you lost the connection with the suit list. As I mentioned before, keep your cards in a list … | |
Re: [QUOTE=DarkFlash;269597]Alright, I figured out how to do it, did some more research and stumbled on the answer [code=python]import ftplib # We import the FTP module session = ftplib.FTP('myserver.com','login','passord') # Connect to the FTP server myfile = open('toto.txt','rb') # Open the file to send session.storbinary('STOR toto.txt', myfile) # Send the file … | |
Re: In MAIN SIZER CONTROL don't add the sizer to a sizer, but the panel: [php]import wx ID_MENU_EXIT = 101 ID_MENU_ABOUT = 102 ID_RADIO_FORWARDS = 201 ID_RADIO_STATIONARY = 202 ID_RADIO_BACKWARDS = 203 class Frame1(wx.Frame): def __init__(self, parent, title): wx.Frame.__init__(self, parent, -1, title, pos=(150, 150), size=(640, 480)) ### MENU ### # Create … | |
![]() | Re: Make sure your dictionary values are unique and immutable when you do this: [code=python]inverted_dict1 = dict([(v, k) for (k, v) in dict1.iteritems()]) [/code] |
Re: The traceback will also give you the line number your error occured in. It is not in the code segment you posted! Look at it carefully! You might have used start and not "start". | |
Re: Here is one way to do it, using slicing, a for loop and indexing with enumerate(): [code]# let's say you read your file in as a string ... str1 = """ 2 h 3 s 6 d Ace s """ list1 = str1.split() print list1 # ['2', 'h', '3', 's', … | |
![]() | Re: Let's return for a moment to the original endeavor on LaMouche's part to learn about dictionaries. Notice that your encode and decode dictionaries are the same. The order of the keys will be decided internally by the dictionary anyway using a hash algorithm to speed up key searches. You could … |
Re: A first quick look revealed a number of things. Give attention to my comments marked with "!!!!". Here is code that should work, so you can improve on it: [code]# this is supposed to be simple # I am trying to simulate combat # As easy as I can # … | |
Re: We just discussed that in one of sneekula's threads: [php]# exercise in argument passing def increment(*args): """receives tuple *args, change to list to process, then back to tuple""" args = list(args) index = 0 for arg in args: args[index] += 1 index += 1 return tuple(args) def main(): c = … | |
Re: Your problem might be one of Networking. There is actually a subforum on DaniWeb called "Linux Web Hosting and Apache" see: [url]http://www.daniweb.com/techtalkforums/forum33.html[/url] | |
![]() | Re: With __cmp__() you can override, overload, customize (whatever you want to call it) the cmp() function for the class instance. There are a bunch of these babies, all starting and ending with double underlines. I think they are also called instance methods. They can do powerful things, but also can … ![]() |
![]() | Re: This tiny code snippet will separate your list and make the alpha list unique. I also added the typical list sort: [php]raw_list = [1, 'a', 2, 'a', 3, 'v', 4, 't', 5, 'v', 9, 'c'] alpha_list = [] number_list = [] for c in raw_list: # make the alpha_list unique … |
Re: Function sleep(seconds) from module time is pretty much the best. Remember seconds is a float so you can delay 0.5 seconds. [code]import time print "Hello ..." time.sleep(2.5) # wait 2.5 seconds print "... there!" [/code] ![]() | |
Re: I think we solved some of this in: [url]http://www.daniweb.com/techtalkforums/post266586-2.html[/url] To sort two lists in parallel you can zip them to a list of tuples, sort that and convert back to two lists again. | |
Re: Here are two Python code smaples using the Tkinter GUI. Each example has a hint how to do the dart game: [php]from Tkinter import * root = Tk() root.title("Archery Target") canvas = Canvas(root, width=600, height=600) canvas.pack() # draw five circles, largest one first, circles draw within a # square with … | |
Re: You can do the whole thing easily with the Python program given at: [url]http://www.daniweb.com/code/snippet499.html[/url] You only need to adjust the last line of the code for your needs. Read the comments carefully! | |
Re: If you are popping the cards off your deck/pack list, the len() should give the number of cards left. Here is an example: [php]import random class Cards(object): def __init__(self): """creates a deck/pack of cards and shuffles it""" suits = ["Hearts", "Diamonds", "Spades", "Clubs"] numbers = ["Ace"] + range(2, 11) + … | |
Re: [QUOTE]%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;C:\Program Files\ATI Technologies\ATI Control Panel;C:\Program Files\QuickTime\QTSystem\;C:\Program Files\Common Files\Adobe\AGL;H:\Python24[/QUOTE] or whatever version of Python you have. Normally you don't have to do this kind of thing, when you install Python properly with the downloaded MSI installer file. | |
Re: Well, a quiz program asking a question and giving multiple choice answers is always entertaining and can be fun, depending on the questions and answers. I think vegaseat suggested something like that in the "Projects for the Beginner" thread. Read through the zip file he attached and you will chuckle! … | |
Re: Use: [code]os.path.exists(filename) # returns True or False [/code]I you don't want to truncate an existing file with 'w' or 'w+' use the 'a' option for append. | |
![]() | Re: Printing with a format string comes in handy with tables. Let's say you have a list of player scores: [code]player_scores = [ ["Freddy", 9234], ["Grace", 8723], ["Nutty Fuddy", 7143], ["Lurcher", 9545]] for ps in player_scores: player = ps[0] score = ps[1] print player, score """ somewhat ugly: Freddy 9234 Grace … ![]() |
Re: This from the Win32 Programmer's Reference: [QUOTE]The GetPixel function retrieves the red, green, blue (RGB) color value of the pixel at the specified coordinates. COLORREF GetPixel( HDC hdc, // handle of device context int XPos, // x-coordinate of pixel int nYPos // y-coordinate of pixel ); Parameters hdc Identifies the … |
The End.