404 Posted Topics
Re: 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 … | |
Re: 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 | |
Re: 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 | |
Re: 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 | |
Re: 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 … | |
Re: Look for a delimiter between the rows and .count() them. Jeff | |
Re: Your code would have to have its own configuration file that it stores the default directory in and then loads on entry. Jeff | |
Re: 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 | |
Re: 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] | |
Re: 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 … | |
Re: (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 … | |
Re: 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 … | |
Re: 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 … | |
Re: 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 … | |
Re: 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 | |
Re: So you want a text box in one window, and what you type in the text box will also show up in another window? | |
Re: 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"}) >>> … | |
Re: 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 | |
Re: 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 … | |
Re: 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 = … | |
Re: 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 … | |
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 … | |
Re: 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? … | |
Re: 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 … | |
Re: 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 … | |
Re: Hm. Are you using httplib to make your connection? Jeff | |
Re: 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 | |
Re: 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 … | |
Re: 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 … | |
Re: 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 | |
Re: Wow, that's weird. [code="Python"] >>> import socket >>> socket.AF_INET 2 >>> [/code] Can you reproduce my results? Jeff | |
Re: 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 = … | |
Re: or even [code=Python] key=lambda x:x[1] [/code] | |
Re: (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 … | |
Re: os.path, if I understand the need correctly. | |
Re: (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': … | |
Re: 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] ? | |
Re: 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 … | |
Re: 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 | |
Re: [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] | |
Re: You'll need an interface module: [url]http://wiki.python.org/moin/DatabaseInterfaces[/url] Pick your fave :) Jeff | |
Re: I strongly recommend making your warrior a class. Then, you can deduct points as needed when damage is taken. Jeff | |
Re: 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 … | |
Re: 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 … | |
Re: 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 | |
Re: 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 |
The End.