Forum: Python Feb 14th, 2009 |
| Replies: 4 Views: 332 Just to add to scru's point: Being able to re-use code is an extremely important but sometimes overlooked feature of programming. Its main value is not saving time, but eliminating bugs.
That is,... |
Forum: Python Jun 6th, 2008 |
| Replies: 2 Views: 481 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}
... |
Forum: Python Apr 4th, 2008 |
| Replies: 10 Views: 1,291 Exactly so. Install PIL from the link above, and then
from PIL import Image, ImageTk
my_im = Image.open("myjpg.jpg")
real_im = ImageTk.PhotoImage(my_im)
and now you can use real_im in... |
Forum: Python Feb 27th, 2008 |
| Replies: 1 Views: 2,860 Hi all,
This is the beginning of a hopefully useful project: to create a Canvas widget for wxPython that will mimic or improve on the Tkinter Canvas widget. Those of you who have coded with both... |
Forum: Python Oct 9th, 2007 |
| Replies: 1 Views: 2,237 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... |
Forum: Python Sep 20th, 2007 |
| Replies: 4 Views: 4,712 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) +... |
Forum: Python Aug 11th, 2007 |
| Replies: 6 Views: 6,029 You can also use read(size) or readlines(size). In both cases, size is the number of bytes to read (approximate for readlines).
Jeff |
Forum: Python Mar 25th, 2007 |
| Replies: 2 Views: 1,834 So I usually test my Tkinter apps from IDLE; in this case, I get the following error message every 'pixel' I scroll:
Traceback (most recent call last):
File... |
Forum: Python Mar 14th, 2007 |
| Replies: 2 Views: 2,266 The code looks good so far.
There is one feature of your code that you might not intend: e and e1 both have the result of the grid() operation, which is None. I'm guessing that you wanted e and... |
Forum: Python Feb 11th, 2007 |
| Replies: 4 Views: 3,889 I'm a bit confused about btn3, since I don't see its code. However, I do notice that btn1 does .bind("<Button-1>",callback).
That's actually overkill and can lead to the problem that you... |
Forum: Python Jan 23rd, 2007 |
| Replies: 15 Views: 2,508 Just a little tweakery needed:
data_raw = """[20 ]
[ 35 ]
[40 ]
[84 ]
[100 ]
[ 245]
[ 260] |
Forum: Python Jan 11th, 2007 |
| Replies: 209 Views: 97,378 Also in the blackjack game: find a way to make the total() function deal with aces in a general way so that vega's worry about adding more aces can be satisfied.
def total(hand):
# how many... |
Forum: Python Jan 1st, 2007 |
| Replies: 6 Views: 2,730 Here's my stab at a quick tutorial:
Validating Input
Any time your program receives input from a device, it needs to check whether the input is valid. By far, the two most common points for... |
Forum: Python Dec 14th, 2006 |
| Replies: 11 Views: 4,274 well, one approach could be to have the button attached to a single callback that checks state and calls one of three functions based on the state:
def callback(self):
commands =... |
Forum: Python Oct 25th, 2006 |
| Replies: 27 Views: 5,061 I have code that attempts to do the same, but it reveals a couple of discrepancies. I'm wondering whether my code is wrong, or if perhaps there's something in your code, LaMouche
# create test... |
Forum: Python Oct 17th, 2006 |
| Replies: 209 Views: 97,378 Project for the advanced: write code to hack into Ene's gem store above from a remote zombie and change all the prices to $19.99.
:lol: |
Forum: Python Oct 17th, 2006 |
| Replies: 209 Views: 97,378 Write a function primes(n) that returns a list of primes less than n.
primes(13)
[2,3,5,7,11]
primes(25.2)
[2,3,5,7,11,13,17,19,23]
If you don't know any clever ways to generate primes,... |
Forum: Python Sep 27th, 2006 |
| Replies: 1 Views: 989 Here is the code that burned me today. I'm re-writing my Sudoku solver to make it more "Pythonic" -- it was my first Python project, and the old code looks like translated C :lol: -- anyways, at one... |
Forum: Python Aug 10th, 2006 |
| Replies: 209 Views: 97,378 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... |