988 Posted Topics

Member Avatar for sneekula

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) …

Member Avatar for Ene Uran
0
119
Member Avatar for sneekula

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 …

Member Avatar for sneekula
0
195
Member Avatar for sneekula

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 …

Member Avatar for sneekula
0
155
Member Avatar for coder_gus
Member Avatar for coder_gus
0
76
Member Avatar for linux

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 …

Member Avatar for vegaseat
0
209
Member Avatar for mattyd

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 …

Member Avatar for jrcagle
0
244
Member Avatar for mattyd
Member Avatar for jrcagle
0
318
Member Avatar for chris99

You need to start a new thread with the proper title and give us the two files, so we can troubleshoot your program!

Member Avatar for Ene Uran
0
140
Member Avatar for shr2408
Member Avatar for vegaseat

So that is where that went to! I thought I saw that for a moment in the stickies.

Member Avatar for mattyd
0
306
Member Avatar for manukumar05

Check out the Py2Exe sticky at: [url]http://forums.devshed.com/python-programming-11/py2exe-step-by-step-guide-209432.html[/url]

Member Avatar for Ene Uran
0
102
Member Avatar for DarkFlash

You can use the Python Image Library module to create thumbnails of images, see: [url]http://www.daniweb.com/code/snippet209.html[/url]

Member Avatar for Ene Uran
0
85
Member Avatar for nnobakht

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.

Member Avatar for nnobakht
0
112
Member Avatar for Matt Tacular
Member Avatar for Matt Tacular
0
209
Member Avatar for mattyd

[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]

Member Avatar for Ene Uran
0
6K
Member Avatar for Matt Tacular

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 …

Member Avatar for Ene Uran
0
89
Member Avatar for dunderhead

You are lucky getting a hold of Robin, the expert with wxPython. Did he ask you to buy his book on wxPython?

Member Avatar for dunderhead
0
1K
Member Avatar for shappell

This is the Python forum, I think you have to post this in the Java forum!

Member Avatar for Ene Uran
0
86
Member Avatar for sneekula

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 …

Member Avatar for Ene Uran
0
3K
Member Avatar for danizzil14

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 …

Member Avatar for Ene Uran
0
219
Member Avatar for ~s.o.s~

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).

Member Avatar for ~s.o.s~
0
402
Member Avatar for UrbanKhoja
Member Avatar for mattyd
0
349
Member Avatar for mruane

Must be your first attempt at ELIZA type AI. The function friends() is called, but does not exist. What is it supposed to do?

Member Avatar for Mouche
0
114
Member Avatar for mruane

Any program with extension .pyw is considered a windows program, not a console program!

Member Avatar for mruane
0
148
Member Avatar for macca1111

[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 + …

Member Avatar for vegaseat
0
136
Member Avatar for sneekula

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 …

Member Avatar for jbennet
0
232
Member Avatar for sneekula

[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]

Member Avatar for ghostdog74
0
466
Member Avatar for mruane

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] …

Member Avatar for Mouche
0
311
Member Avatar for macca1111

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 …

Member Avatar for macca1111
0
183
Member Avatar for DarkFlash

[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 …

Member Avatar for Ene Uran
0
93
Member Avatar for MarkWalker84

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 …

Member Avatar for MarkWalker84
0
435
Member Avatar for Mouche

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]

Member Avatar for Ene Uran
0
302
Member Avatar for mruane

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".

Member Avatar for Ene Uran
0
136
Member Avatar for macca1111

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', …

Member Avatar for macca1111
0
317
Member Avatar for Mouche

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 …

Member Avatar for Ene Uran
0
532
Member Avatar for mruane

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 # …

Member Avatar for vegaseat
0
173
Member Avatar for macca1111

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 = …

Member Avatar for Ene Uran
0
83
Member Avatar for gbs

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]

Member Avatar for Ene Uran
0
117
Member Avatar for Mouche

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 …

Member Avatar for Mouche
0
108
Member Avatar for Mouche

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 …

Member Avatar for vegaseat
0
164
Member Avatar for HLA91

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]

Member Avatar for Mouche
0
344
Member Avatar for macca1111

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.

Member Avatar for Ene Uran
0
127
Member Avatar for theking11

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 …

Member Avatar for Ene Uran
0
3K
Member Avatar for mruane

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!

Member Avatar for Ene Uran
0
99
Member Avatar for macca1111

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) + …

Member Avatar for Ene Uran
0
115
Member Avatar for HLA91

[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.

Member Avatar for vegaseat
0
198
Member Avatar for mruane

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! …

Member Avatar for Ene Uran
0
116
Member Avatar for akadri

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.

Member Avatar for katharnakh
0
94
Member Avatar for Mouche

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 …

Member Avatar for Mouche
0
150
Member Avatar for Matt Tacular

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 …

Member Avatar for vegaseat
0
128

The End.