Posts
 
Reputation
Joined
Last Seen
Ranked #348
Strength to Increase Rep
+10
Strength to Decrease Rep
-2
95% Quality Score
Upvotes Received
31
Posts with Upvotes
22
Upvoting Members
16
Downvotes Received
1
Posts with Downvotes
1
Downvoting Members
1
15 Commented Posts
~505.29K People Reached
Favorite Forums
Favorite Tags
Member Avatar for linux

The info on the links is not encouraging: "very little code was written in 2005, and 2006 doesn't look much better." Hmm... My mildly informed $0.02, for the purpose of generating lively discussion: I don't think a true OS can be written in Python, for the following reason: Python requires …

Member Avatar for Thulan
2
2K
Member Avatar for jrcagle

Hi all, The continuing quest to master Tkinter has led to this implementation of the dots and boxes game. The rules are well-known: each player gets to create a new line between two dots (single-click near the line you wish to create). If a player creates a box, he gets …

Member Avatar for Jiten_1
-1
6K
Member Avatar for mattyd

Right. Notice the subtle difference and be careful about it: the original code is legitimate Python, but it doesn't mean what one might think it means. [code] if var1 == "image0.GIF" or "image1.GIF" or "image2.GIF": varValue = 10 [/code] will take the value of 'var1 == "image0.GIF"' (which might be …

Member Avatar for rahul_64
0
53K
Member Avatar for RMartins

Or, [code="Python"] if math.sqrt(n) % 1 == 0: print "integer square root!" else: print "not." [/code]

Member Avatar for pythonBasic
0
717
Member Avatar for pyguy25

That's a good start. I might do something like [code=Python] ... for ch in message: code_val = ord(ch) + key if code_val > ord('z'): code_val -= 26 # better: ord('z') - ord('a'), just in case len(alphabet) != 26 codedMessage = codedMessage+chr(code_val) ... [/code] Jeff

Member Avatar for FaZeSkwlSh00ter
0
7K
Member Avatar for sneekula

[quote=sneekula;274491]Are there any guidelines when to use and not to use a class?[/quote] (1) Well, one of the most important prerequisites for having clean code is to use the right data structure. A class can help you construct the data structure that you need instead of having to force something …

Member Avatar for Vineetha_1
0
4K
Member Avatar for vegaseat

Here's one that I actually wrote for home use cataloging several thousand pictures: Write a program to scan a user-supplied directory for .jpg files. Then, output the list of files, sorted by date picture was taken, as an HTML file with hyperlinks to each pic. Bonus points: make the scan …

Member Avatar for vegaseat
20
18K
Member Avatar for vegaseat
Member Avatar for sneekula
0
3K
Member Avatar for sneekula

It's a good question, and my own private peace with it is that .destroy() appears to be more general: widgets and frames can be destroyed without destroying the parent, but if you .quit() anywhere within the widget tree, it appears to kill the whole toplevel. Here's some sample code. The …

Member Avatar for entropicII
0
44K
Member Avatar for katharnakh

This is a partial solution, but I want to try to figure it out, 'cause it's a cool problem. If you use an Entry() widget for the password and then set show='*' in the Entry widget, the Control-c will only copy the ******s rather than the underlying characters. That would …

Member Avatar for Gribouillis
0
2K
Member Avatar for ALJ

So in the manual, it says [quote]Of course, Python doesn't use 8-bit numbers. It USED to use however many bits were native to your machine, but since that was non-portable, it has recently switched to using an INFINITE number of bits. Thus the number -5 is treated by bitwise operators …

Member Avatar for klickagent
0
9K
Member Avatar for jrcagle

Generators are essentially dynamic sequences, making their official debut in Python 2.5. That got me to thinking: can we make a circular list with them? Why yes, we can...

Member Avatar for vegaseat
2
187
Member Avatar for pinbustersrule

In terms of putting items into a list to be sorted, you want this: [code=Python] f = open("mytextfile","r") mylist = [] for line in f: mylist.append(f.readline()) f.close() [/code] or even more concisely, [code=Python] f = open("mytextfile","r") lines = f.readlines() f.close() [/code] I agree with woooee, but he's not refusing help: …

Member Avatar for noonecares
0
885
Member Avatar for chris99

Good job! Some testing results: 1) Starting in the foyer and going n, e, w leads to an endless loop of "invalid command" -- no commands, even help, are recognized. 2) Starting in the foyer and going e, followed by "look", gives this: There is an open wardrobe in the …

Member Avatar for Jacklittle01
0
1K
Member Avatar for aot

I'm not sure you'll get meaningful results from anything mouse-and-keyboard driven *because* the mouse and keyboard events can sometimes take unpredictable amounts of time to be passed along to your program. I'm not a hardware expert, so I could be wrong about that ... but at least keep the possibility …

Member Avatar for BBTK
0
9K
Member Avatar for Eclipse77

Well, just to give you a bit of confidence ... the prof has given you good advice. Now for the details ... ! First, you need to plan your code. Make a plan (sometimes called [I]pseudocode[/I]) that doesn't go into the details, but clearly and generally spells out exactly how …

Member Avatar for woooee
0
3K
Member Avatar for Noliving

Does win.getMouse() wait for the mouse to be clicked before it returns? If not, then you may have a problem ... because it will fire 5 times instantaneously, and get the same mouse coordinates for p1 through p5. Jeff

Member Avatar for Karsam
-1
4K
Member Avatar for MarkWalker84

It almost seems like what you need is a simple C function to write the char to the port, and then link it in to your Python program. Jeff

Member Avatar for mr_snarf
0
2K
Member Avatar for skix

Check the documentation for tkFileDialog with help(tkFileDialog) and help(tkFileDialog.askopenfile). That will tell you what the dialog accepts as parameters and returns as values. Jeff

Member Avatar for Notouch
0
11K
Member Avatar for sneekula

If you're looking to test really large numbers, here's an implementation of the Rabin-Miller probabilistic test: [code=Python] def primes(n): """ primes(n) --> primes Return list of primes from 2 up to but not including n. Uses Sieve of Erasth. """ if n < 2: return [] nums = range(2,int(n)) p …

Member Avatar for wallars
0
1K
Member Avatar for MakingMoney

Preliminary tip: encase your code in (code="Python) and (/code) tags (no spaces on the first tag) so that it'll look pretty. This is a classic case of recursion: fib(n) = fib(n-1) + fib(n-2) The best way to compute it is therefore recursively: >>> def fib(n): if n <= 0: return …

Member Avatar for TrustyTony
0
2K
Member Avatar for AnjaliThukral

reinstall! Wow. I've gotten that message before, but rebooting is the most extreme solution to date for me. It may be the case that your firewall is blocking connections to IP address 127.0.0.1, the internal loopback that Python uses. If so, you can go into Symantec/Norton/McCaffee/whatever and enable Python on …

Member Avatar for vegaseat
-1
1K
Member Avatar for MrKnowNothing

Here's what your prof meant: let s = "refer" then s[0] == s[-1], so we check s = "efe" and s[0] == s[-1], so we check s = "f" and s[0] == s[-1], so we check "" which is empty, so we're done, and we return True. So what you …

Member Avatar for Rehab A
0
304
Member Avatar for FreezeBlink
Member Avatar for night_guard

The super() function allows you to access methods in the parent x that are shadowed by methods of the same name in the child y. In this case, y.__init__ wants to call x.__init__. But the problem is that y.__init__ clobbers __init__ in the namespace; that is, x.__init__ doesn't get inherited. …

Member Avatar for Gribouillis
0
180
Member Avatar for gusbear
Member Avatar for Roadphantom13

I'm confused. I agree with the change; == is almost always better than is. Still and all... [code="Python"] >>> a = 2 >>> a is 1 False >>> a is 2 True >>> if a is 1: print "a is 1!" else: print "a is not 1!" a is not …

Member Avatar for forsakenedzero
0
5K
Member Avatar for jobs

Apparently so. You can check it: [code="Python"] >>> a = ((11L,), (12L,), (13L,), (14L,), (15L,), (16L,), (17L,), (18L,), (19L,), (20L,)) >>> print a[0] (11L,) >>> print a[0][0] 11 >>> print type(a[0][0]) <type 'long'> >>> [/code] Jeff

Member Avatar for timogoosen
0
3K
Member Avatar for jrcagle

So I was thinking that there would be a simple Pythonic way to delete a directory structure. My app creates and deletes user accounts, which may contain any number of subdirectories and files. Hence, I wanted to do something like: [code] os.rmdir(user_directory) [/code] BUT...that throws an error when user_directory is …

Member Avatar for pythonista
0
137
Member Avatar for sneekula

Or if regular expressions are too painful, some kind of compromise: [code] def count_caps(s): d = {} caps = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" for i in caps: d[i] = s.count(i) return d def print_caps(s): d = count_caps(s) # not 'for i in d' becuase dictionaries don't have guaranteed order for i in "ABCDEFGHIJKLMNOPQRSTUVWXYZ": …

Member Avatar for twekberg
0
317