Forum: Python Mar 11th, 2009 |
| Replies: 12 Views: 1,042 Reasonable people of good will can disagree on such matters, but it is pretty well recognized that parameters and return values are superior to global variables. I'd take out the global sock and pass... |
Forum: Python Mar 11th, 2009 |
| Replies: 12 Views: 1,042 You'd put the bt_connect() before you put up the app menu, so the user first sees a list of bt devices and chooses one. You connect to that, carefully checking that the connect() succeeded. I think... |
Forum: Python Mar 10th, 2009 |
| Replies: 4 Views: 504 Some people might look at that and think opportunity! Google Summer of Code is coming up. Can daniweb.com be a mentoring organization? |
Forum: Python Mar 9th, 2009 |
| Replies: 3 Views: 454 return count is indented too far. |
Forum: Python Mar 7th, 2009 |
| Replies: 12 Views: 1,042 I noticed you have defined receive()twice. This means the first definition is discarded and only the second one counts.
Do you need receive()at all? It depends on what you're doing. Normally you'd... |
Forum: Python Mar 1st, 2009 |
| Replies: 1 Views: 265 Does it really just hang, or perhaps return the wrong error code?
Usually when I run into this kind of problem I telnet to port 21 and type in the USER and PASS commands manually. Try this; you... |
Forum: Python Feb 28th, 2009 |
| Replies: 9 Views: 1,044 ... and thank sb3700 for closing the loop here. Six months from now somebody else will have the identical problem and with a bit of googling will see the solution, thus reducing global aggravation. |
Forum: Python Feb 26th, 2009 |
| Replies: 7 Views: 687 ... you should not use random as your variable name. Pick something different, say rand or rnum or whatever. Otherwise you overwrite your imported random module the first time you assign something to... |
Forum: Python Feb 25th, 2009 |
| Replies: 9 Views: 1,044 I don't know the answer but suggest two things to consider:
Sending all four lines in one write() may burst data faster than the receiver can actually handle.
You might check on the newlines in... |
Forum: Python Feb 21st, 2009 |
| Replies: 3 Views: 1,976 Thanks for the example, VE. I have a .tar.bz2 file I need to read within Python and was able to take your code and use it. I've put together a little .tar.bz2 extraction example in case others follow... |
Forum: Python Feb 19th, 2009 |
| Replies: 1 Views: 501 The datetime object takes a series of integers, not a single string:>>> t1 = datetime.datetime(2009,12,22,22,22)
>>> t2 = datetime.datetime(2009,12,22,20,22)
>>> (t1-t2).days
0
>>>... |
Forum: Python Feb 18th, 2009 |
| Replies: 1 Views: 219 The jargon for this is "transpose a matrix".
I did this interactively (pay careful attention to the brackets):>>> import numpy
>>> M = numpy.matrix([['A', '1', '2', '3', '4', '5', '6', '7', '8',... |
Forum: Python Feb 16th, 2009 |
| Replies: 7 Views: 1,168 ...
p = choice(array) #CHOOSE A PARTICLE,P, AT RANDOM FROM THE ARRAY
pnewx=p.x + 0.05*(random() -0.5) #GENERATE A STEP IN X
pnewy=p.y + 0.05*(random() -0.5) #GENERATE A STEP IN Y
... |
Forum: Python Feb 16th, 2009 |
| Replies: 10 Views: 1,092 Good explanation, Jeff.
I don't really have a good handle on Python's type() function, but you can use it as ff:>>> str(type(56))
"<type 'int'>"
>>> str(type('ABC'))
"<type 'str'>"
>>>... |
Forum: Python Feb 13th, 2009 |
| Replies: 9 Views: 1,000 Possibly not the easiest to explain, but a completely different approach would be "".join([ [letr.lower(),letr.upper()][letr in 'aeiou'] for letr in list("whatever was input") ]) |
Forum: Python Feb 13th, 2009 |
| Replies: 4 Views: 276 For even more fun, learn some SQL. There's even Python code to access SQL databases, but I would suggest first some interactive basics with (free) mySQL. (You quickly learn why there's a software... |
Forum: Python Feb 12th, 2009 |
| Replies: 6 Views: 509 The statement if win_loss_code == 'W' or 'w': doesn't parse the way you want. Try if win_loss_code == 'W' or win_loss_code == 'w': and do the corresponding for Ll.
The way it is currently written... |
Forum: Python Feb 12th, 2009 |
| Replies: 4 Views: 333 if i1==True: is exactly the same as if i1:, just as if i1==False:is identical to if not i1:
So if you want to test elif i1 and i2 == False: you should write elif not i1 and not i2: or equivalently... |
Forum: Python Feb 12th, 2009 |
| Replies: 4 Views: 333 No, things don't group the way your code expects. In particular, elif i1 and i2== False: parses as elif (is==True) and (i2==False):. You would need parentheses to change the grouping from the... |
Forum: Python Feb 9th, 2009 |
| Replies: 4 Views: 1,437 Doesn't the 'f' come second in the numpy.array() call? |
Forum: Python Feb 8th, 2009 |
| Replies: 5 Views: 433 For spacing, try print ' ' * 15 + 'CRAPS'. Also, the word is "lose" not "loose". Where you say while roll == roll: you probably should just say while True: since that is the canonical way of setting... |
Forum: Python Feb 4th, 2009 |
| Replies: 5 Views: 730 I use 'T' instead of '10', but you can change this as neededimport random
rank = random.choice( ('A','2','3','4','5','6','7','8','9','T','J','Q','K') )
suit = random.choice( ('c','d','h','s') )... |
Forum: Python Jan 23rd, 2009 |
| Replies: 13 Views: 740 Because a and b have no value when you go to calculate pythag.
The statement pythag=(a**2+b**2)**0.5 is, after all, just a bunch of arithmetic operations resulting in a value that is stored in... |
Forum: Python Jan 22nd, 2009 |
| Replies: 13 Views: 740 Not to be a blanket-wetter, but I noticed you have pythag=(a**2+b**2)**0.5 before the statements that give values to a and b. The program as presented will not run without minor edits.
Still, it... |
Forum: Python Jan 19th, 2009 |
| Replies: 3 Views: 328 Use a tuple of the two words as dictionary index. Piece of cake.
Of course you have to figure out how to separate the words from the HTML, but there's plenty of libraries out there. |
Forum: Python Jan 12th, 2009 |
| Replies: 10 Views: 1,315 Definitely the first one (directly after the writing loop). Wise of you to ask. |
Forum: Python Jan 12th, 2009 |
| Replies: 10 Views: 1,315 One more thing: you probably need to add code.stdout.close() after you are done with the subprocess output. In this case, probably right after the for loop that writes out the lines. That file was... |
Forum: Python Jan 11th, 2009 |
| Replies: 10 Views: 1,315 file.write(code)is wrong. Replace with:
for line in code.stdout: # code.stdout is handle to subprocess output
file.write(line)This should get you closer. |
Forum: Python Jan 11th, 2009 |
| Replies: 10 Views: 1,315 I don't know what that "it" is you are trying to write to the file. You seem to want to write the output of the program being run, but I don't think you can do that with .call() which just returns... |
Forum: Python Jan 6th, 2009 |
| Replies: 11 Views: 762 I don't see how this can work, since dashes is initially undefined: while y != g:
dashes += " _"
y += 1
Perhaps replace that code with the simpler dashes = g * " _"? |
Forum: Python Jan 4th, 2009 |
| Replies: 4 Views: 649 This will get you started, but there are many things you need to consider beyond the core function.def password_input(prompt, pw):
while True: # Forever
data = raw_input(prompt)
... |
Forum: Python Dec 31st, 2008 |
| Replies: 3 Views: 577 I don't think this is true! Since the list is 0-based, child1 is the child of root, but child2 is the child of child1. (You know, 2/2 is 1, not 0 :-). This skews things right from the start.
One... |
Forum: Python Dec 30th, 2008 |
| Replies: 3 Views: 577 Using the secret ... tags, we get:
def main():
def Parent(i):
return i/2
def Left(i):
return 2*i
def Right(i):
return 2*i+1
def Heapify(A, parent,... |
Forum: Python Dec 23rd, 2008 |
| Replies: 2 Views: 1,013 Doesn't look like a Python problem -- looks like a network problem. Are you sure your new server's network configuration is set up like the old one's? (Both hardware connections and software... |
Forum: Python Dec 17th, 2008 |
| Replies: 3 Views: 764 Probably only Guido knows for sure. This topic has come up a lot in the past. An if/elif chain is as concise as switch/case and allows for tests other than equality, so in some sense is more... |
Forum: Python Dec 11th, 2008 |
| Replies: 4 Views: 474 As I understand it, the 2.x print statement syntax is illegal in 2.6 when the new print function is desired, and always illegal syntax in 3.0. (I think that's what #1 meant when he said "breaks old... |
Forum: Python Dec 11th, 2008 |
| Replies: 2 Views: 357 Nice code. Almost there. Here's a hint: evolved_array[iy,ix]==1 does NOT assign any value to evolved_array[iy,ix]. But you seem to be trying to do that. Blame it on your editor... |
Forum: Python Dec 6th, 2008 |
| Replies: 2 Views: 1,284 Problem is you're naming your output variable random. Use another name!
After you do your import random you've defined an object named random that basically contains a bunch of procedures such as... |
Forum: Python Dec 5th, 2008 |
| Replies: 4 Views: 675 I too suggest the use of % to check for zero remainder, avoiding floating point in this problem.
A nit on operators: when you want integer-style division, discarding any remainder, the proper... |
Forum: Python Dec 2nd, 2008 |
| Replies: 8 Views: 927 That doesn't square with what you said in the original post ... you know ... the part that reads "I can't seem to figure it out." For all I know, English isn't your native language. Just wanted to... |