Forum: Python 7 Days Ago |
| Replies: 1 Views: 83 Re: subtype custom 'float'. How to? I would probably take a completely different approach:
class MyFloat(float):
def __new__(self, name, value):
return float.__new__(self, value)
def __init__(self, name, value):
... |
Forum: Python 9 Days Ago |
| Replies: 1 Views: 94 Re: receive bytes streams The function "unpack" is not a built-in function. Does your code import some module at the top?
Jeff |
Forum: Python 11 Days Ago |
| Replies: 16 Views: 401 Re: If <not number>? Or this:
try:
val = int(item)
if val > 0:
do stuff for positive numbers
elif val < 0:
do stuff for negative numbers
else: # don't omit zero! |
Forum: Python 12 Days Ago |
| Replies: 4 Views: 201 |
Forum: Python 15 Days Ago |
| Replies: 8 Views: 188 Re: subscript and superscript help! Good news: the convention for scientific notation
2.72e-2 (which is the correct rendering)
is so well-recognized that superscripting is not required.
Jeff |
Forum: Python 15 Days Ago |
| Replies: 2 Views: 201 Re: Class getters and setters Just to jlm's good points above, the getter and setter functions allow the object to control access to its own data members.
For instance, suppose you have a sprite that can rotate. Clearly, if the... |
Forum: Python 15 Days Ago |
| Replies: 4 Views: 201 |
Forum: Python 15 Days Ago |
| Replies: 2 Views: 397 |
Forum: Python 15 Days Ago |
| Replies: 5 Views: 253 Re: Memory Error WRT to the main problem, the memory error, I agree that there's something wrong, and it doesn't appear to be your code.
You might try e-mailing the PIL support at
image-sig@python.org
Jeff |
Forum: Python 15 Days Ago |
| Replies: 5 Views: 253 Re: Memory Error Well, a quick tangential note: your method for extracting the extension
name[-4:]
is buggy. What if the file extension is ".jpeg"?
Better:
filename, ext = os.path.splitext(name) |
Forum: Python 16 Days Ago |
| Replies: 1 Views: 99 Re: Pygame Well, that depends. Do you want to end up coding games? If so, then start!
http://www.pygame.org/news.html
The "tutorials" link on the left should be helpful
Jeff |
Forum: Python 28 Days Ago |
| Replies: 3 Views: 278 |
Forum: Python Jun 5th, 2008 |
| Replies: 2 Views: 183 Re: keys problem Well, that question may not have an answer if the values are not unique; for example, if
book['key1'] = {'keya':valuea, 'keyb':valueb}
and
book['key2'] = {'keya':valuec, 'keyd':valued}
then... |
Forum: Python Jun 4th, 2008 |
| Replies: 5 Views: 198 Re: Surely there's a better way? If you are determined to iterate through the original list ... and there are times when that's appropriate ... then you must iterate through a copy of the list:
>>> nums = [1.0,2.0,3.0,4.0,5.0]
>>>... |
Forum: Python Jun 4th, 2008 |
| Replies: 4 Views: 219 |
Forum: Python Jun 3rd, 2008 |
| Replies: 4 Views: 255 |
Forum: Python Jun 3rd, 2008 |
| Replies: 2 Views: 240 Re: Can't hear PMIDI Is there a chance that the sound is playing on the wrong sound device? I have two sound cards (built in and recording equipment), and sometimes my software gets confused.
Jeff |
Forum: Python Jun 3rd, 2008 |
| Replies: 1 Views: 235 Re: pymssql reconnect to db if connection dies Seems to me that this line ought to be an error...
c=Cursor()
because you then try to execute commands on it ... but it's not assigned to any database, right?
Maybe I'm misunderstanding.
Jeff |
Forum: Python Jun 3rd, 2008 |
| Replies: 2 Views: 152 |
Forum: Python Jun 3rd, 2008 |
| Replies: 5 Views: 306 |
Forum: Python May 29th, 2008 |
| Replies: 1 Views: 201 Re: Network help Yes, the standard way of writing a shell (which is what you are doing) is like this:
while True:
inputline = raw_input(myprompt)
parse inputline into command, operands
if command ==... |
Forum: Python May 29th, 2008 |
| Replies: 1 Views: 115 Re: Question about Crap Game What you've done is to make the game itself into your main code. If you think about it, that's not what you want. The main loop here is
playerscore = housescore = 0
while user wants to play:
... |
Forum: Python May 29th, 2008 |
| Replies: 1 Views: 150 Re: battleships First, please use the 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... |
Forum: Python May 27th, 2008 |
| Replies: 2 Views: 222 Re: problems with pygame The appropriate code tags are
## code here
What's happening? I'm guessing that the sound plays, but then the code hangs after that?
Jeff |
Forum: Python May 27th, 2008 |
| Replies: 4 Views: 253 Re: python network simulator No, I think it's clear enough. class Network should inherit from object, though. Only old-style classes get to be parent-less.
class Network(object):
...
Jeff |
Forum: Python May 26th, 2008 |
| Replies: 5 Views: 306 |
Forum: Python May 25th, 2008 |
| Replies: 8 Views: 404 |
Forum: Python May 25th, 2008 |
| Replies: 1 Views: 169 Re: If and Else 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... |
Forum: Python May 25th, 2008 |
| Replies: 8 Views: 404 Re: Running a program by double-click (windows) Two things:
(1) I can double-click on your program and get a nice little Hello, World window, along with the command-prompt window. Do you get something else?
(2) If you manually rename the file... |
Forum: Python May 25th, 2008 |
| Replies: 7 Views: 374 |
Forum: Python May 25th, 2008 |
| Replies: 8 Views: 404 |
Forum: Python May 25th, 2008 |
| Replies: 7 Views: 374 Re: Removing everything inbetween '<>' well, you might consider the BeautifulSoup module.
link:
http://www.crummy.com/software/BeautifulSoup/
It has the capability to extract tags and values relatively easily.
Jeff |
Forum: Python May 24th, 2008 |
| Replies: 6 Views: 339 |
Forum: Python May 24th, 2008 |
| Replies: 6 Views: 339 |
Forum: Python May 24th, 2008 |
| Replies: 2 Views: 233 Re: keep os.chdir() after exit? Your code would have to have its own configuration file that it stores the default directory in and then loads on entry.
Jeff |
Forum: Python May 24th, 2008 |
| Replies: 1 Views: 185 Re: Batch files and termination of program 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... |
Forum: Python May 24th, 2008 |
| Replies: 4 Views: 209 |
Forum: Python May 24th, 2008 |
| Replies: 2 Views: 193 Re: Varible change Detection There's a second way to think about this as well, and it's well adapted to real-time operating systems (read: robotics).
Suppose you have a speaker object, a listener object, and a thinker object... |
Forum: Python May 24th, 2008 |
| Replies: 2 Views: 193 Re: Varible change Detection what about
class MySpeechParser(...):
self.topic = "Dinosaurs"
sentence = self.GetSentence()
topic = self.DiscernTopic(sentence)
if topic != self.topic:
speaker.Speak("You... |
Forum: Python May 24th, 2008 |
| Replies: 1 Views: 202 Re: Working on a little program 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
del shots[8:]
return shots |