Posts
 
Reputation
Joined
Last Seen
Ranked #1K
Strength to Increase Rep
+8
Strength to Decrease Rep
-2
100% Quality Score
Upvotes Received
29
Posts with Upvotes
24
Upvoting Members
16
Downvotes Received
0
Posts with Downvotes
0
Downvoting Members
0
8 Commented Posts
2 Endorsements
Ranked #621
Ranked #355
~185.67K People Reached
PC Specs
Debian Linux stock kernel 2.4.25 on a Dell Inspiron XPS
Favorite Forums
Favorite Tags

94 Posted Topics

Member Avatar for vegaseat

While Python offers flexible [I]container[/I] data structures, such as lists and dictionaries, it is occasionally helpful to create our own. Suppose, for example, that we wanted to create a data structure with two dictionaries: one for key-value pairs where len(key) is even, and one for key-value pairs where len(key) is …

Member Avatar for vegaseat
23
34K
Member Avatar for vegaseat

Write a simple calculator in Python. The program should accept an arithmetic expression from the command-line, then recursively parse it to produce a numerical value. Like many programming projects, this one can be done in phases: i) First, make the program parse only basic arithmetic. This means expressions that use …

Member Avatar for vegaseat
20
18K
Member Avatar for EriCartman13

Hi EriCartman13, If you want to create a random number between 1 and 100, the conventional way of doing that in Python is:[CODE]import random x = random.randint(1,100)[/CODE]I would swap this code in and remove the for loop. The resulting program creates a random integer between 1 and 100, assigns that …

Member Avatar for bumsfeld
-1
4K
Member Avatar for bumsfeld

You mean something like this?[CODE]import re f = dict() f["compile"] = re.compile f["findall"] = re.findall f["match"] = re.match pattern = f["compile"]("[\\w]+")[/CODE]This works for me.

Member Avatar for Kyss
0
240
Member Avatar for Micko

[I]...and that is .exe program that can be run on different machines.[/I] That's not necessarily true. Compiling a C/C++ program does not create a universal executable that can be installed on any machine. Whether the executable will work on your friend's machine depends on (a) what the program does, and …

Member Avatar for darkside2205
0
327
Member Avatar for ram.patil

Hi ram.patil, A Hardy-Ramanujan number is a number which can be expressed as the sum of two positive cubes in exactly two different ways. For example, 1729 is equal to the sum: 1^3+12^3 - or alternatively, to the sum: 9^3+10^3 - but not to any other sums of positive cubes. …

Member Avatar for TrustyTony
0
2K
Member Avatar for G-Do

Hi guys, I'm trying to learn the principles of artificial intelligence. I just finished coding up a belief net and a corresponding EM algorithm that learns the CPTs for latent nodes using training data (if you're unfamiliar with the lingo, you're probably going :eek: right now). While the program (written …

Member Avatar for Gael Varoquaux
0
332
Member Avatar for G-Do

Here's something of mine that might actually be useful: a Python implementation of the K-means clustering algorithm. I wrote something similar last year in Java for a school project, and decided to rewrite it in Python this summer for practice. The purpose of the algorithm is to discover internal structure …

Member Avatar for woooee
2
1K
Member Avatar for Ene Uran

Hi Ene Uran, There are two ways of doing this. The first way: use the textvariable option in the Label constructor to set the Label text to the value of a StringVar maintained elsewhere in your program. Then, in your callback function, change the value of the StringVar and the …

Member Avatar for vegaseat
0
3K
Member Avatar for eleonora

Hi eleonora, Statements like this:[CODE]board[(x,y)] == "R"[/CODE]with a double equals sign (==) only test to see whether the value at (x,y) is "R"; that statement does not [I]assign[/I] "R" to board[(x,y)], which is what you want to do. Instead, use board[(x,y)] = "R" and it should remember the moves. Also …

Member Avatar for TrustyTony
0
3K
Member Avatar for Avner .H.

Hi Avner .H., I can't help you with your first problem, other than to say "why not put the Bash code in a Bash script?" which I guess is not an option for you, or else you would have done it. However, I can help with the second item: grabbing …

Member Avatar for sneekula
0
861
Member Avatar for G-Do

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 many times as you want. It's your job to …

0
862
Member Avatar for G-Do

[URL="http://www.bitstorm.org/gameoflife/"]Life[/URL] is a "game" or cellular automaton - an evolving computational state system - developed by a Cambridge mathematician named John Conway. The idea is simple: start with a board of dimensions (x,y). Populate the board with an initial pattern of occupied and empty cells. In every turn, the rules …

0
1K
Member Avatar for G-Do

Suppose you are a medical researcher studying diabetes. Your boss has given you a big chart of data from diabetes patients. Each row of the chart has information for one patient. Each column of the chart is a health-related statistic, such as height, weight, age, blood pressure, cholesterol level, etc. …

2
1K
Member Avatar for G-Do

Here's a cute little encipher/decipher program with a Tkinter GUI I wrote a while back. It's an implementation of a derivative of the Vigenere algorithm; the algorithm is taken from Laurence Smith's Cryptography: The Science of Secret Writing, Amazon link here. It's a dated book (and the technique itself is …

0
258
Member Avatar for a1eio

You could always make a .exe file that calls the Python script, then rename that to .scr, right?

Member Avatar for Stefano Mtangoo
0
2K
Member Avatar for jmroach

Hi jmroach, You're going to want to use an sqlite [URL="http://www.sqlite.org/pragma.html"]pragma statement[/URL]. A pragma statement lets you query database meta-data or in some cases alter the behavior of the database. The pragma that gives you column headers is called "table_info." In the example you gave below, you would use it …

Member Avatar for weisburd
0
24K
Member Avatar for gusbear

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, and inside it printing "Compute" or something like that. The API for the graphics …

Member Avatar for hobbz86
0
139
Member Avatar for rysin

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 sockets to send data from one computer to another. An example is given …

Member Avatar for EAnder
0
100
Member Avatar for Edwards8

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 [URL="http://mail.python.org/pipermail/image-sig/1999-April/000713.html"]here[/URL]. I don't know if this will work for TIFs, but you can …

Member Avatar for woooee
0
436
Member Avatar for zachabesh

Hi zachabesh, Can't you just use os.path.getsize()? You call it with the name of the file as an argument.

Member Avatar for zachabesh
0
133
Member Avatar for sibdizzle

Hi sidbizzle, So if I am understanding your code correctly, you are trying to set up a program that prints a welcome prompt with a menu, then allows the user to deposit or withdraw from an account. The amount of money in the account is stored in acctHist.data, along with …

Member Avatar for G-Do
0
195
Member Avatar for linux

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 creating a pygame Surface for each of the 10x10 image tiles, then stick all your Surfaces …

Member Avatar for linux
0
144
Member Avatar for G-Do

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 lines of code, but I buttressed that with a lot of comments and …

Member Avatar for nish88
0
117
Member Avatar for nish88
Member Avatar for G-Do

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 [I]really[/I] don't want to enter the equations in by hand. Thanks.

Member Avatar for jrcagle
0
101
Member Avatar for RMartins

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 need many more than 10**7. Actually, you'll only need to perform 10,015,005 computations, …

Member Avatar for G-Do
0
86
Member Avatar for Carlo Gambino

Hi Carlo Gambino, The straightforward way of doing this is:[CODE=python]g = [ 1, 2, 3, 4 ] h = [] for i in range(len(g)+1)[1:]: h.append(g[i-1]+i) print h[/CODE]Alternatively, you could just use a list comprehension:[CODE=python]print [ g[i-1]+i for i in range(len(g)+1)[1:] ][/CODE]Hope this helps!

Member Avatar for jrcagle
0
143
Member Avatar for StepIre

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:[CODE=python]import pickle # If you want to store a dictionary in a file... d = { "a":"aardvark", "b":"ball", "c":"centurion" } f = open("somefile.dat", "w") …

Member Avatar for StepIre
0
130
Member Avatar for trihaitran

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 superclass with a "template method" and a subclass with a "hook method." The template method in the superclass contains all …

Member Avatar for G-Do
0
119
Member Avatar for G-Do

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 of five colored dice without peeking at the code. The snippet is …

Member Avatar for jrcagle
0
198
Member Avatar for nirmalarasu

Hi nirmalarasu, I think [URL="http://wiki.python.org/moin/Freeze"]freeze[/URL] is what you're looking for.

Member Avatar for G-Do
0
2K
Member Avatar for gusbear

[QUOTE=gusbear;525524]i get to down as far as the tax equation and it won't run, any ideas??[/QUOTE]I have an idea, and that idea is "please wrap your program in code tags."

Member Avatar for jrcagle
0
115
Member Avatar for Begjinner
Member Avatar for woooee
0
125
Member Avatar for gawain_

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:[CODE=python]import sys inp = sys.stdin.readline() while inp.strip() != "": print inp # Do your calculations right here inp = sys.stdin.readline()[/CODE]Stolen from [URL="http://www.dalkescientific.com/writings/NBN/python_intro/io.html"]here[/URL]. It doesn't …

Member Avatar for gawain_
0
151
Member Avatar for msaenz

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 this using the Python xml module, please see my modifications to your …

Member Avatar for msaenz
0
2K
Member Avatar for nish88

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 callback function. The way to do that in Tkinter is:[CODE=python]canvas.bind("<Button-1>", …

Member Avatar for G-Do
0
237
Member Avatar for rysin

Hi rysin, Can you open the file at all from within python? If you say[CODE=python]f = open("C:\\orb\\backroundorb.jpeg", "r")[/CODE]does that work?

Member Avatar for rysin
0
100
Member Avatar for Valmian

Hi Ilya, If you want to do interactive simulations, I think you might be better off checking out [URL="http://www.pygame.org"]pygame[/URL], which is designed for games but can easily be adapted for this kind of thing. I have written simple 2D epithelial tumor growth simulations in pygame - I can't imagine how …

Member Avatar for Valmian
0
7K
Member Avatar for jforell

Hi John, If I understand things correctly, then first off, line 10 is wrong. Instead of saying[CODE=python]print "After year", n[/CODE]you ought to say[CODE=python]print "After year", i[/CODE]because the variable that represents the current year in the for-loop is i, not n, which is the total number of years. Also, are you …

Member Avatar for ZZucker
0
102
Member Avatar for seamus.boyle

Hi seamus.boyle, The problem is in line 5:[CODE=python]im3 = Image.composite('im1','im2',"L")[/CODE]See, what you're doing is sending the [i]string literals[/i] "im1" and "im2" as arguments to the function Image.composite(). But Image.composite() doesn't want string literals - it wants actual image objects, the variables themselves! Get rid of the single quotes and you …

Member Avatar for seamus.boyle
0
221
Member Avatar for gtselvam

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 which is destroyed once the call returns. In other words, suppose you write a python script called …

Member Avatar for Duoas
0
221
Member Avatar for balance

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, you see that the error is in line 15 of UbuntuPackageGrabber.py, the main script. That line says:[CODE]source = urllib.urlopen(url).read()[/CODE]where …

Member Avatar for G-Do
0
109
Member Avatar for eleonora

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 "board" and you want to dump it to a file called "board.dat" you can just …

Member Avatar for G-Do
0
330
Member Avatar for eleonora

Hi eleonora, I am assuming that this is like a big game of tic-tac-toe, where the first player to get four in a row wins. You need to decide three things first: (i) are you going to do this using just the command prompt or are you going to use …

Member Avatar for G-Do
0
2K
Member Avatar for bumsfeld

Hi bumsfeld, I believe that the array data structure in the Numeric/NumPy package is both typed and non-resizable, just like C arrays (actually, I'm pretty sure that these data structures [I]are[/I] C arrays wearing a Python hat). Check out: [URL=http://numeric.scipy.org]http://numeric.scipy.org[/URL]

Member Avatar for vegaseat
0
13K
Member Avatar for time4biking

Remotely connecting to other systems by invoking external bash commands is cumbersome, isn't it? You'd be better served by learning how to use the paramiko package, which lets you do the same thing but from within Python: [URL="http://www.lag.net/paramiko"]http://www.lag.net/paramiko[/URL] Check out the instructions that come with the package for short demos …

Member Avatar for BearofNH
0
127
Member Avatar for jrcagle

Hi jrcagle, I would have said to give the ghost a memory of his last choice, then exclude the opposite of that choice as a possibility when deciding which way to go in the present decision. In other words, if the ghost just decided to move east, don't let him …

Member Avatar for G-Do
0
2K
Member Avatar for mattyd

Hi mattyd, Does that image represent a pygame game wrapped inside a Tkinter widget? Is that what you're trying to do? Running pygame and Tkinter together can be tricky, as both open new threads that listen for user input, and threading bugs are always the hardest to squash. Without seeing …

Member Avatar for mattyd
0
189
Member Avatar for jimmypk

Hi jimmypk, It might be easier if you maintained a 'parent' field in each Node, then used this to forcibly unlink subtrees from parent Nodes. In that case, deleting a Node would be similar to deleting a Node in a linked list - set the parent's child field to the …

Member Avatar for G-Do
0
140

The End.