- Strength to Increase Rep
- +10
- Strength to Decrease Rep
- -2
- Upvotes Received
- 31
- Posts with Upvotes
- 22
- Upvoting Members
- 16
- Downvotes Received
- 1
- Posts with Downvotes
- 1
- Downvoting Members
- 1
Re: 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 … | |
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 … | |
Re: 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 … | |
Re: Or, [code="Python"] if math.sqrt(n) % 1 == 0: print "integer square root!" else: print "not." [/code] | |
Re: 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 | |
Re: [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 … | |
Re: 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 … | |
Re: Do you have a link for this particular algorithm? Thanks, Jeff | |
Re: 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 … | |
Re: 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 … | |
Re: 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 … | |
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... | |
Re: 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: … | |
Re: 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 … | |
Re: 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 … | |
Re: 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 … | |
Re: 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 | |
Re: 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 | |
Re: 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 | |
Re: 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 … | |
Re: 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 … | |
Re: 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 … | |
Re: 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 … | |
Re: 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. … | |
Re: 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 … | |
Re: 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 | |
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 … | |
Re: 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": … |