404 Posted Topics

Member Avatar for budstar

First, please use the [noparse][code="Python"][/code][/noparse] tags to enclose your code. That will preserve your indentation. More importantly, your code: The first thing that strikes me is that your Tank1() and Tank2() classes contain exactly the same code. Therefore, you don't need both. Instead, you can do this: [code="Python"] class Tank …

Member Avatar for jrcagle
0
140
Member Avatar for supra87

Start with Tkinter. It's not my favorite (wxPython), but it's the easiest to get started with. Demo: [code="Python"] import Tkinter as tk mainw = tk.Tk() mainw.frame = tk.Frame(mainw) mainw.frame.button = tk.Button(mainw.frame, text="Press Me!") mainw.frame.button.grid() mainw.frame.grid() mainw.mainloop() [/code] Manuals here: [url]http://infohost.nmt.edu/tcc/help/pubs/tkinter/tkinter.pdf[/url] [url]http://infohost.nmt.edu/tcc/help/pubs/tkinter/[/url] Jeff

Member Avatar for left_shoe
0
353
Member Avatar for lllllIllIlllI

well, you might consider the BeautifulSoup module. link: [url]http://www.crummy.com/software/BeautifulSoup/[/url] It has the capability to extract tags and values relatively easily. Jeff

Member Avatar for bumsfeld
0
106
Member Avatar for Kabooom

Actually, it probably does something and then closes the window immediately -- which means you can't see it! Try this: [code="Python"] print "Hello, World" raw_input("Press <Enter> to exit.") [/code] If you double-click this, you should get output in a command prompt window. Jeff

Member Avatar for Kabooom
0
3K
Member Avatar for tondeuse34

That code won't work. Here's why: "or" doesn't mean "one of these" in Python, or any other computing language. Instead, "or" means "True if one or both operands is True; False if both are False." So apply that rule to what you wrote: "choice == help" [b]or[/b] "/help" Since the …

Member Avatar for jrcagle
0
122
Member Avatar for ymf
Member Avatar for muney13
Member Avatar for Miyuki

Your code would have to have its own configuration file that it stores the default directory in and then loads on entry. Jeff

Member Avatar for jrcagle
0
207
Member Avatar for jhaski

It can be due to any exception whatsoever. To find out, you'll need to isolate the offending lines. I often run my code through IDLE, which prints exceptions. There might be another solution that works. Jeff

Member Avatar for jrcagle
0
104
Member Avatar for Seagull One

what about [code="Python"] class MySpeechParser(...): self.topic = "Dinosaurs" sentence = self.GetSentence() topic = self.DiscernTopic(sentence) if topic != self.topic: speaker.Speak("You wanna stay on topic, yo?") if response == "No": self.topic = topic [/code]

Member Avatar for jrcagle
0
102
Member Avatar for Novasie

I'm sorry ... I'm really unclear about the rules of this game. I notice a couple of things that you can streamline. * The lines [code="Python"] del shots[8:] return shots [/code] can be reduced to [code="Python"] return shots[8:] [/code] because you don't want to actually change the shots array within …

Member Avatar for jrcagle
0
107
Member Avatar for nclouse

(1) Welcome! (2) Why can't you send a text control packet? (3) Wouldn't it make more sense to have the client timeout and restart? That way, if the client times out (no matter the cause -- server goes down, 5-year-old with scissors cuts the cat5e cable, etc.), then it will …

Member Avatar for ich1
0
199
Member Avatar for Mackjan

Instead of debugging, if it's OK, I'll talk about *how* to debug. Since the error is coming from line 42 (line 31 in the code above), insert a print statement just prior to line 31: [code="Python"] ... pile = dela(c) print pile ordna(pile) [/code] That way, you can check your …

Member Avatar for woooee
0
157
Member Avatar for bosko

This is odd. Each method already knows its own name. For example: [code="Python"] class A(object): def a1(self): self.calledMethod = "a1" def a2(self): self.calledMethod = "a2" [/code] That is, when you call a function or method, the instruction pointer knows which code block it's currently in. So what is it that …

Member Avatar for bosko
0
102
Member Avatar for behshad312
Member Avatar for sanoski

You want to learn about classes first. Python is designed to be an object-oriented language for a reason: classes give your program structure and therefore help reduce debugging time. From there, you will need to learn, probably in this order: * Tkinter (or wxPython, but Tkinter is easier) * the …

Member Avatar for jrcagle
0
97
Member Avatar for zls11610

Some options ... [b]Empty dictionary[/b] [icode]d = dict()[/icode] or [icode]d = {}[/icode] [b]Dictionary with predefined values[/b] [icode]d = {1: "Hi there", 2: "Good-bye"}[/icode] [b]Dictionary from a list of tuple pairs[/b] [code="Python"]mypairs = ((1,"Hi there"), (2, "Good-bye")) d = dict(mypairs) [/code] Jeff

Member Avatar for praveen_web
0
3K
Member Avatar for tondeuse34

So you want a text box in one window, and what you type in the text box will also show up in another window?

Member Avatar for tondeuse34
0
94
Member Avatar for froboi

I would recommend a class: [code="Python"] >>> class Drink(object): def __init__(self, name, ingr_list): self.ingr_list = ingr_list def __str__(self): s = ", ".join([self.ingr_list[x] + " of " + x for x in self.ingr_list]) return s >>> d = Drink("Ozone", {"Amaretto":"1.5 oz", "beer": "Splash", "Sweet and sour": "3 oz", "Sprite": "Splash"}) >>> …

Member Avatar for jrcagle
0
179
Member Avatar for happimani

Well, the error message indicates that Python thinks you don't have the correct admin level login. Were you installing with the correct permissions? Jeff

Member Avatar for jrcagle
0
128
Member Avatar for gotm

Well, I would recommend checking out the csv module import csv help(csv) in the Python docs. It can do what Shadow is recommending pretty much automatically. I would also recommend getting your menu working first, just as a stub. The options don't have to do anything, but if you have …

Member Avatar for jrcagle
0
140
Member Avatar for jmroach

What's happening is that dictionaries, like lists, are mutable objects. Furthermore, they are assigned by reference and not by value. So under certain conditions, you might think you are changing one mutable object when in fact you are changing all of the ones that are referenced: [code="Python"] >>> a = …

Member Avatar for jmroach
0
153
Member Avatar for tondeuse34

If you're talking about mouse clicks in Tkinter, then you will want to check out the manual: [url]http://infohost.nmt.edu/tcc/help/pubs/tkinter/tkinter.pdf[/url] OR in HTML format [url]http://infohost.nmt.edu/tcc/help/pubs/tkinter/[/url] [url]http://www.pythonware.com/library/index.htm[/url] To get mouse clicks, check out the Bind method at the end of the manual. To handle file dialogs, check out the tkFileDialog module. Hope that …

Member Avatar for tondeuse34
0
2K
Member Avatar for jrcagle

So I have this nifty wxPython widget -- a Cartesian Coordinate plane with scrolling ability. Three issues: (1) On scrolling outwards, I set it to resize itself, which seemed like a reasonable plan. But the resizing is very choppy. Is there any way to capture the last wx.SIZE event instead …

0
82
Member Avatar for tefflox

More details, please. Here's what I think I understand: * You want the script to download the photos, * Execute the mogrify command, and * rename and print a validation page. So: where are the photos currently? At a URL? on the user's HDD? You want to rename the photos? …

Member Avatar for jrcagle
0
126
Member Avatar for Shadow14l

It's probably a \r character. In any event, you can determine its value like this: [code="Python"] snip = data[:100] (high enough number to include at least one offending character) for char in snip: print char, ord(char) [/code] That'll give you the ASCII value of your character, and then you can …

Member Avatar for Shadow14l
0
108
Member Avatar for tkpython

Images can be a slight pain in Tkinter because only certain formats are supported. The work-around is to install Python Imaging Library, PIL. So: what image formats do you have? And, where do you want the images to go? I couldn't quite tell from the code. Also, are you trying …

Member Avatar for ZZucker
0
183
Member Avatar for swaroopk85
Member Avatar for lllllIllIlllI

I used this one: [url]http://209.85.215.104/search?q=cache:LDExvZ8s7DEJ:heather.cs.ucdavis.edu/~matloff/Python/PyNet.pdf+Python+network+programming&hl=en&ct=clnk&cd=1&gl=us&client=firefox-a[/url] This one looks decent: [url]http://www.amk.ca/python/howto/sockets/[/url] Jeff

Member Avatar for jrcagle
0
113
Member Avatar for Mackjan
Member Avatar for Seagull One

My money's on a bug in speaker.Speak() OR on an improperly installed wxPython module. Here's why: Your line chooses a random item from Health2, which is presumed to be a list. If Health2 is not a list, then random.choice throws a TypeError, which is not your issue. Further, random.choice() is …

Member Avatar for Seagull One
0
387
Member Avatar for ssDimensionss

I'm a little confused about the use of the "num" variable. I would probably do this: [code="Python"] import urllib import csv temp_url = urllib.urlopen("http://app.lms.unimelb.edu.au/bbcswebdav/courses/600151_2008_1/datasets/finance/asx_2007.csv") data = csv.reader(temp_url) header = data.next() earnings = [(row[0], float(row[6])) for row in data] earnings.sort(key = lambda x: x[1]) earnings.reverse() earnings = earnings[:10] [/code] line 6 …

Member Avatar for jrcagle
0
3K
Member Avatar for swaroopk85

Do you need low-level access? Simply opening a page is easy enough... [code="Python"] import urllib2 f = urllib2.urlopen("http://www.google.com") data = f.read() f.close() [/code] Do you need something schnazzier than that? Jeff

Member Avatar for swaroopk85
0
100
Member Avatar for Acidburn

Wow, that's weird. [code="Python"] >>> import socket >>> socket.AF_INET 2 >>> [/code] Can you reproduce my results? Jeff

Member Avatar for jrcagle
0
81
Member Avatar for heshan

The listening part is the challenging bit. Are you planning on running a background thread or something? Anyways, you'll end up doing something like this: [code="Python"] old_dir = os.listdir("mytargetdir") while True: new_dir = os.listdir("mytargetdir") for x in new_dir: if x not in old_dir: f = open("mytargetdir/"+x) exec f old_dir = …

Member Avatar for heshan
0
93
Member Avatar for wandie
Member Avatar for tondeuse34

(1) Have you checked out the "Projects for the Beginner" page? (2) Decide on some programs you might find useful or fun, and write them. This year's projects for me include a weather database with GUI, PacMan, Defender, a wxCanvas module, and a networked Go Fish game. (3) pick an …

Member Avatar for tondeuse34
0
96
Member Avatar for Miyuki
Member Avatar for crackers

(1) Use the [b][noparse][code="Python"][/noparse][/b] and [b][/code][/b] tags to format your code correctly. (2) WRT your code, walk through line-by-line. [code="Python"] print \ ''' a - Rock b - Paper c - Scissors ''' choice1 = raw_input("Choice: ") print if choice1 == 'a': print 'You picked rock' elif choice1 == 'b': …

Member Avatar for ZZucker
0
141
Member Avatar for oldSoftDev

So you want something like this (formatting not to scale!): [code="output"] Prime Non-prime 2 3 5 7 1 4 6 8 11 13 17 19 9 10 12 14 [/code] ?

Member Avatar for jrcagle
0
100
Member Avatar for CFrances

First, the usual rejoinder: use the '[code=Python ]' and '[/code ]' tags to make your posts look pretty. Now for the code: why not turn main() into a function called game() that returns True for a win and False for a loss. Then you can run a for loop and …

Member Avatar for CFrances
0
3K
Member Avatar for Munki87

You really want to make your character a class object. That's what object-oriented coding is all about. Then, you can simply subtract the damage from self.health and all will work fine. Jeff

Member Avatar for jrcagle
0
92
Member Avatar for guvengunes

[url]http://www.google.com/search?q=magic+square+algorithms&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:en-US:official&client=firefox-a[/url]

Member Avatar for jrcagle
0
100
Member Avatar for blade321
Member Avatar for krishnasaradhi

You'll need an interface module: [url]http://wiki.python.org/moin/DatabaseInterfaces[/url] Pick your fave :) Jeff

Member Avatar for BearofNH
0
198
Member Avatar for cam9856

I strongly recommend making your warrior a class. Then, you can deduct points as needed when damage is taken. Jeff

Member Avatar for jrcagle
0
107
Member Avatar for marceta

I think you want a dictionary, if I understand correctly. The dictionary is the standard way of mapping one set of items to another. So you have mydict = {URL1: 13, URL2: 0, URL3: 3, URL4: 2, ...} And then you run this bit of code: [code="Python"] for URL in …

Member Avatar for jrcagle
0
176
Member Avatar for knish

I don't have that module, but it looks like action is a function that is called; name would probably be a string name for the display; args would be a tuple of args to supply to the action, and kw would be a dictionary of keyword arguments to supply. So …

Member Avatar for jrcagle
0
167
Member Avatar for Xlphos

I'm guessing that what you want is an event loop: [code="pseudo"] while True: check for events respond to events [/code] and then all of your many while loops could be separate events. What do you have in mind? Jeff

Member Avatar for woooee
0
143
Member Avatar for drjekil

It is a bit tricky. Can you explain the problem more precisely? For example, what do each of the fields in the string "1lghB H i 71.9 H H -19.94" mean? Jeff

Member Avatar for drjekil
0
165

The End.