169 Posted Topics

Member Avatar for mathijs

Start here: [code=Python] keys = mydict.keys() # List of keys keys.sort() # Sorts keys[] in-place for k in keys: print k, mydict[k] [/code]

Member Avatar for mathijs
0
148
Member Avatar for jobs

[quote=jobs;452505]Only one default_age variable is created for all instance of class Student and self.default_age means every instances of class Student gets a variable default_age?[/quote] No. In your example you've defined variable [inlinecode]Student.default_age[/inlinecode] which has nothing to do with any [B]default_age[/B] property that a class instance may have. The class instance …

Member Avatar for BearofNH
0
181
Member Avatar for MrShoot

[quote=MrShoot;446985] (...)Now let me complicate this a bit more. What if I only want to lowercase all the letters but the first letter from each string included in the list? For example, we have: [code=python]list = ["CAnADA", "hELLO", "CAN"][/code] I want it to show up like: ["Canada", "hello", "Can"] [/quote] …

Member Avatar for Ene Uran
0
161
Member Avatar for Eclipse77

Thanks for reading the guidelines. Most of what you need is in the Python date library. Take a look at [URL]http://docs.python.org/lib/datetime-date.html[/URL] for starters. You'd want to do something like: [code=Python] import datetime d = datetime.date(2007,10,5) print d.weekday() [/code] Note the arguments to datetime.date() are integers, not strings. (Hint: there's an …

Member Avatar for jrcagle
0
175
Member Avatar for jobs

Thank you for reposting via [code] tags, and using an appropriate title. td is an instance, not a string. You probably want to say `price = re.compile('[0-9]*\.[0-9]*').search(td.contents[0])`, and/or iterate over `td.contents[] (via [inlinecode]for tdc in td.contents:`, say). You know, of course, that you can write something like `mypat = re.compile('[0-9]*\.[0-9]*')` …

Member Avatar for BearofNH
0
543
Member Avatar for deck55

I suggest a list of lists. It's pretty straightforward, but this being Friday afternoon and all: [code=Python] S = 'S' D = 'D' N = 'N' data = [S,D,S,D,S,D,N,S,D,S,D,N] lists = reduce(lambda x,y: (eval(["x[-1].append(y)","(x[-1].append(y),x.append([]))"][y==N]),x)[1], data, [[]])[:-1] print lists [/code] Produces: [code] [['S', 'D', 'S', 'D', 'S', 'D', 'N'], ['S', 'D', …

Member Avatar for deck55
0
93
Member Avatar for thompsongunner

On my i386 PC you need to reverse the "address" and "is_command" values to shift the 1 to the far left. It's easy enough to make up a union to output what you want. It should be easy to convert [I]any[/I] structure to a byte array but I don't know …

Member Avatar for thompsongunner
0
3K
Member Avatar for trudge

You may need \r\n at the end of your lines instead of just \n. Have you looked into PyWeb, which is designed to do what you want? I can't speak to how well it does what you want, but surely it merits a look.

Member Avatar for trudge
0
149
Member Avatar for gratefulluke

Given:[INDENT][COLOR=Red]#!/usr/bin/python2.3[/COLOR] ... >>> from ZODB import FileStorage, DB Traceback (most recent call last): File "<stdin>", line 1, in <module> [COLOR=Red] ImportError: No module named ZODB[/COLOR] >>> ... My configuration is as follows: [COLOR=Red] Python 2.5.1[/COLOR] [/INDENT]It looks like you problem stems from not having the right version of ZODB installed …

Member Avatar for sharma_vivek82
0
614
Member Avatar for fonzali

Request: [quote=katharnakh;419562] post the code with proper indentation. [/quote] Response: [quote=fonzali;420016]this is how it was written on the internet , all in one line , I just paste and copied it[/quote] fonzali, what kind of excuse is that? katharnakh made a reasonable request; getting the line breaks and indents right …

Member Avatar for fonzali
0
1K
Member Avatar for bergy_nj

The way your code works, if you just type [B]progname data.log[/B] , this statement will be active [inlinecode]if user == 0 and summary == 0 and total == 0:[/inlinecode] and you will see the usage() output. So your program is behaving properly, even if it's not what you want. If …

Member Avatar for BearofNH
0
219
Member Avatar for Ozipto

I would try incrementally removing some of the functions from the scope of parse(). Sooner or later Python will stop complaining and you'll have a better idea where your problem lies. At that point even if you can't figure out why you're getting the error, you'll have a much better …

Member Avatar for Ozipto
0
410
Member Avatar for fredzik

One way is to use time.time() to read a timestamp, as in [inlinecode]tstart=time.time()[/inlinecode]. This returns a floating point number of seconds since some unimportant starting point. Then in your game you periodically check to see if time.time() is greater than [inlinecode]tstart+120.0[/inlinecode] , and quit if that's true.

Member Avatar for fredzik
0
96
Member Avatar for dummies2

> what is wrong with the code. Several things, actually. What is the stray quote doing in: [inlinecode]font-family: Arial, sans-serif; font-size: 11pt">[/inlinecode] ? But I suspect the real problem is here: [inlinecode]print """<option value = [COLOR=red]%d[/COLOR]>%s, %s</option>""" \ % ( [COLOR=red]author[ 0 ][/COLOR], author[ 2 ], author[ 1 ] )[/inlinecode] …

Member Avatar for BearofNH
0
152
Member Avatar for Matt Tacular

[CODE]>>> str3 = str1 + '\' + str2 >>> print str3 c:\documents and settings\user\desktop\starcraft.exe >>>[/CODE]

Member Avatar for ghostdog74
0
184
Member Avatar for Matt Tacular

Perhaps add near the start of main(): [INLINECODE]found = False[/INLINECODE] and add the last line to this sequence: [CODE=python] print "File found -->", trueResult deleteFileSearched() found = True[/CODE] ... and change [INLINECODE]return True[/INLINECODE] at the end of main() to [INLINECODE]return found[/INLINECODE]. So [B]found[/B] starts out "False" meaning "none found" and …

Member Avatar for jrcagle
0
111
Member Avatar for time4biking

I've successfully used telnetlib (included in Python, I believe) in similar cases. Telnet is a more primitive remote-terminal protocol which suffers from a number of security issues, one reason why SSH was developed. If you can use paramiko then by all means do so. But if you run into problems …

Member Avatar for BearofNH
0
127
Member Avatar for Gumster

Try [B]if comp in locals()[locals()['user']]:[/B][code] >>> Rock = ("Scissors","Fire","Snake","Human","Wolf","Sponge","Tree") >>> user = 'Rock' >>> locals()['user'] 'Rock' >>> locals()[locals()['user']] ('Scissors', 'Fire', 'Snake', 'Human', 'Wolf', 'Sponge', 'Tree') >>> comp = 'Sponge' >>> if comp in locals()[locals()['user']]: ... print "In there!" ... else: ... print "Not there." ... In there! >>> [/code] This …

Member Avatar for jrcagle
0
104
Member Avatar for fredzik

This comes pretty close to eliminating the whitebox: [code] # this your input area enter1 = Entry(root, width=82, bg="Beige", borderwidth=0) [/code] , at least on my system where the default background is approximately beige. Also, I would only have the green bar up there when there's something to say. I.e., …

Member Avatar for fredzik
0
2K

The End.