Forum: Python Jul 11th, 2008 |
| Replies: 5 Views: 2,435 Hi Edwards8,
It turns out that PIL will let you read pieces of an image file in sequence without loading the entire thing into memory. Fred Lundh has a post about it on a python mailing list here... |
Forum: Python Jun 24th, 2008 |
| Replies: 2 Views: 976 Hi zachabesh,
Can't you just use os.path.getsize()? You call it with the name of the file as an argument. |
Forum: Python Jun 16th, 2008 |
| Replies: 10 Views: 1,461 Hi count_chockula,
You can indeed edit a dictionary. You would load the dictionary with pickle.load(), then add a new key-value pair, then dump it again, like so:f = open("filename.txt", "r")
d =... |
Forum: Python Jun 16th, 2008 |
| Replies: 10 Views: 1,461 Hi count_chockula,
The file is being overwritten because your file handles are created with an option of "w" which is short for "write." To add extra data to a file without overwriting, you need... |
Forum: Python Jun 14th, 2008 |
| Replies: 10 Views: 1,461 Hi count_chockula,
First of all, class definitions do not have parentheses after them. So:class pettyAccount():should be:class pettyAccount:
Second of all, why are you asking the user for the... |
Forum: Python Jun 10th, 2008 |
| Replies: 2 Views: 687 Hi linux,
Yes, that is definitely possible. I've done something similar from within both pygame and Tkinter (I used Tkinter to design a GUI program for map editing). You would want to begin by... |
Forum: Python May 15th, 2008 |
| Replies: 4 Views: 7,469 Hi jmroach,
You're going to want to use an sqlite pragma statement (http://www.sqlite.org/pragma.html). A pragma statement lets you query database meta-data or in some cases alter the behavior of... |
Forum: Python Mar 18th, 2008 |
| Replies: 4 Views: 1,242 Hi nish88,
Are you running the program from the command line? It needs to be given two command-line parameters (width and height) or it will shut down immediately. |
Forum: Python Mar 13th, 2008 |
| Replies: 4 Views: 1,242 Hi nish88,
Search in this forum for "game of life." |
Forum: Python Mar 2nd, 2008 |
| Replies: 1 Views: 689 Hi all,
Are there any python modules which contain functions for getting the roots of a quartic (degree 4) polynomial? I don't think NumPy has anything like it, and I really don't want to enter... |
Forum: Python Feb 28th, 2008 |
| Replies: 6 Views: 905 Hi RMartins,
This has less to do with Python and more to do with mathematics, but I'll say it anyway.
As jrcagle said, 10**20 is a huge number of iterations to perform. Lucky for you, you won't... |
Forum: Python Feb 22nd, 2008 |
| Replies: 2 Views: 538 Hi StepIre,
You could use the pickle module, which serializes and saves data structures, effectively allowing you to skip the whole messy business of file parsing. Example:import pickle
# If... |
Forum: Python Feb 20th, 2008 |
| Replies: 7 Views: 1,951 Hi Carlo Gambino,
The straightforward way of doing this is:g = [ 1, 2, 3, 4 ]
h = []
for i in range(len(g)+1)[1:]:
h.append(g[i-1]+i)
print hAlternatively, you could just use a list... |
Forum: Python Feb 20th, 2008 |
| Replies: 2 Views: 580 Hi trihaitran,
Use the "template method" software design pattern!
Here's how it works: we're going to split that function of yours across two different functions in two different classes: a... |
Forum: Python Feb 19th, 2008 |
| Replies: 1 Views: 669 Hi all,
I added a new script to the code snippets page. This time, it's a logic puzzle called "Petals Around the Rose." The goal is for you to infer what algorithm is being used to "score" rolls... |
Forum: Python Feb 19th, 2008 |
| Replies: 0 Views: 2,816 Hi all,
Have you ever heard of "Petals Around the Rose?" It's a logic puzzle. The way it works is, I roll five dice, then tell you what the "score" is for this round. I can repeat this for you as... |
Forum: Python Feb 11th, 2008 |
| Replies: 4 Views: 1,912 Hi nirmalarasu,
I have to say, doing things this way runs counter to the Linux philosophy. You shouldn't be trying to smuggle a mutilated Python interpreter (plus whatever modules you need) onto... |
Forum: Python Feb 10th, 2008 |
| Replies: 4 Views: 1,912 Hi nirmalarasu,
I think freeze (http://wiki.python.org/moin/Freeze) is what you're looking for. |
Forum: Python Feb 7th, 2008 |
| Replies: 5 Views: 719 I have an idea, and that idea is "please wrap your program in code tags." |
Forum: Python Feb 6th, 2008 |
| Replies: 10 Views: 2,866 Hi gawain_,
Unfortunately I can't tell you how to do what you're asking without seeing the files you're working on. Python isn't magic - it can't figure out where page breaks are supposed to go... |
Forum: Python Feb 6th, 2008 |
| Replies: 10 Views: 2,866 Hi gawain_,
To answer your first question, you have it backwards. The conditional expression which controls the while loop is (inp.strip() != "") - a boolean expression, one which resolves to... |
Forum: Python Feb 5th, 2008 |
| Replies: 10 Views: 2,866 Hi gawain_,
Why are you reading input using stdin? Why not use one of python's input commands? If you're set on using stdin, you could try this:import sys
inp = sys.stdin.readline()
while... |
Forum: Python Feb 4th, 2008 |
| Replies: 3 Views: 2,945 Hi msaenz,
Lardmeister is correct in that your check for the symbol token "UPS" is flubbed. His approach works fine if you want to treat the whole XML file as a string. However, if you want to do... |
Forum: Python Feb 4th, 2008 |
| Replies: 4 Views: 1,090 Hi nish88,
The string "<Button-1>" is a Tkinter shorthand for "the left mouse button." Incorporate the code I supplied into your Tkinter application and run it, and you will see. |
Forum: Python Feb 2nd, 2008 |
| Replies: 6 Views: 1,028 Well, firstly... (http://www.answers.com/firstly&r=67)
(ducks) |
Forum: Python Feb 1st, 2008 |
| Replies: 7 Views: 829 Hi rysin,
Maybe try importing os and run os.listdir() on the given directory. Do the following and please tell me what you get:import os
os.listdir("C:\\orb")Or maybe it could be some kind of... |
Forum: Python Feb 1st, 2008 |
| Replies: 7 Views: 829 Hi rysin,
Can you open the file at all from within python? If you sayf = open("C:\\orb\\backroundorb.jpeg", "r")does that work? |
Forum: Python Jan 31st, 2008 |
| Replies: 2 Views: 1,317 Hi all,
I add a pygame implementation of the Game of Life to the Code Snippets section. I was actually kind of surprised that we didn't already have one in there! The program only has about 60... |
Forum: Python Jan 31st, 2008 |
| Replies: 0 Views: 4,566 Life (http://www.bitstorm.org/gameoflife/) is a "game" or cellular automaton - an evolving computational state system - developed by a Cambridge mathematician named John Conway.
The idea is... |
Forum: Python Jan 30th, 2008 |
| Replies: 4 Views: 1,090 Hi nish88,
I'm not sure I understand what you mean. Do you want to click on the canvas, then have an oval pop up where you clicked? It sounds like you need to bind mouseclicks on the canvas to a... |
Forum: Python Jan 30th, 2008 |
| Replies: 3 Views: 6,034 Hi Ilya,
If you want to do interactive simulations, I think you might be better off checking out pygame (http://www.pygame.org), which is designed for games but can easily be adapted for this kind... |
Forum: Python Jan 30th, 2008 |
| Replies: 3 Views: 740 Hi John,
If I understand things correctly, then first off, line 10 is wrong. Instead of sayingprint "After year", nyou ought to sayprint "After year", ibecause the variable that represents the... |
Forum: Python Jan 10th, 2008 |
| Replies: 6 Views: 899 Hi rysin,
Unless there's a high-level python module that takes care of chat-type stuff for you (and if there is, I don't know about it), you're going to have to learn how to use client and server... |
Forum: Python Jan 10th, 2008 |
| Replies: 4 Views: 1,470 Hi gusbear,
Are you using the Zelle graphics module? If you are, I think you should try the following strategy. Create a GraphWin, then in one of the corners make a button by drawing a rectangle,... |
Forum: Python Jan 3rd, 2008 |
| Replies: 5 Views: 2,942 Hi gtselvam,
I hate to say this, but I think what you want to do is impossible due to operating system limitations. If memory serves, the os.system() function call creates a forked environment... |
Forum: Python Jan 3rd, 2008 |
| Replies: 2 Views: 1,283 Hi seamus.boyle,
The problem is in line 5:im3 = Image.composite('im1','im2',"L")See, what you're doing is sending the string literals "im1" and "im2" as arguments to the function... |
Forum: Python Dec 6th, 2007 |
| Replies: 3 Views: 4,842 Hi balance,
You should open a command prompt, navigate to the directory where the script is, and invoke it by saying:python UbuntuPackageGrabber.py URL_GOES_HERESubstitute the package URL you have... |
Forum: Python Dec 6th, 2007 |
| Replies: 3 Views: 4,842 Hi balance,
How are you running it?
The error occurs because the "downloader" module, urllib, has a urlopen() function which doesn't recognize the URL being passed in. If you step backwards,... |
Forum: Python Dec 3rd, 2007 |
| Replies: 2 Views: 1,024 Hi eleonora,
It's also easy to use the pickle module. Pickle dumps objects into a data file and reloads them without you having to worry about parsing text. So, if you have a variable named... |
Forum: Python Dec 1st, 2007 |
| Replies: 10 Views: 2,769 Hi eleonora,
Really? I just ran it and it stops correctly. The print_board() function did need some tweaking to make the board come out okay, and the x index was off by one (meaning, the first... |