python

Running python on a Windows machine vs Linux

Hello, I am interested in learning python but my linux skills suck. i would like to develop a medium to large scale web application using python and django but afraid the software may not work well on a windows box. Is there a performance difference in running python on linux vs windows. Is there anything that I should watch out for when...

Monkey patch Python class

I've got a class, located in a separate module, which i can't change. from module import MyClass class ReplaceClass(object) ... MyClass = ReplaceClass This doesn't change MyClass anywhere else but this file. However if I'll add a method like this def bar(): print 123 MyClass.foo = bar this will work and foo method will be a...

Run Python CGI Script on Windows XP

This exact question has been asked before but I am at my wits end! I've spend 4 hours trying to get a SIMPLE Python CGI script to work on Windows XP but I get errors. Please save my sanity! Python Script register.py #!c:/Python30/python.exe -u print "Content-type: text/html" print "<P>Hello, World!</p>" Script is located in: C:\Pr...

Command+W Support in wxPython

It's my understanding that in wxPython in OSX, ⌘+w support for closing wx.Window objects. In order to add it, I've had to bind to wx.EVT_KEY_DOWN, checking for event.MetaDown() and event.KeyCode == 'W' explicitly. In my app, I need to have all windows and dialogs support this. I'm still in the process of layout out my GUI, but I got to ...

Python Array with String Indices

Is it possible to use strings as indices in an array in python? For example: myArray = [] myArray["john"] = "johns value" myArray["jeff"] = "jeffs value" print myArray["john"] ...

using extended ascii characters for wikimedia api

I am writing a simple search algorithm for wikipedia. I am having trouble when I send a query with characters that have accents and other characters that are not seen in regular english. Queries that return in error are: http://en.wikipedia.org/w/api.php?action=query&amp;titles=Albrecht%20Dürer&amp;prop=links&amp;pllimit=33&amp;format=xm...

Signal handler, python

I have a multithreaded program and use the signal.signal(SIGINT,func) to kill all threads when ctrl c is pressed. The question I have is this: I have to call signal.signal(...) from main in python. Do I have to call that on a loop or can I just set it once and whenever the user presses ctrl c, the signal will be caught? ...

stop person moving through walls using Python

Possible Duplicate: stop moving through wall in maze using Python How can I do this using Python 3.1: use the current cell, check if there is a wall to the right, left, up, down etc. This is my code for moving: if event.keysym == 'Right': print( 'moving to the right', c) c.move(CELLSIZE,0) I tried this code to stop...

MapReduce on more than one datastore kind in Google App Engine

I just watched Batch data processing with App Engine session of Google I/O 2010, read some parts of MapReduce article from Google Research and now I am thinking to use MapReduce on Google App Engine to implement a recommender system in Python. I prefer using appengine-mapreduce instead of Task Queue API because the former offers easy it...

Implement a userEdited signal to QDateTimeEdit?

QLineEdit has a textEdited signal which is emitted whenever the text is changed by user interaction, but not when the text is changed programatically. However, QDateTimeEdit has only a general dateTimeChanged signal that does not distinguish between these two types of changes. Since my app depends on knowing if the field was edited by th...

How to sort with lambda

Trying to sort by date with lambda I can't understand which lambda my error message is referring to. The message is <lambda>() takes exactly 1 argument (2 given) The 2 instructions are a = A.proximity_fetch(A.all().filter("modified >", timeline).filter("published =", True).filter("modified <=", bookmark ).order("-modified") ,db.GeoPt...

Using Mercurial to separate three versions: official/development/testing/

Hello: I'm working on deploying a Python module composed of several dozen files and folders; I use Mercurial for managing the software changes. I want to keep the same module in three branches: the official one (which the team uses), the development one (this may be more than one development branch), and the testing branch (not the tes...

Python - Speed up generation of permutations of a list (and process of checking if permuations in Dict)

I need a faster way to generate all permutations of a list, then check if each one is in a dictionary. for x in range (max_combo_len, 0, -1): possible_combos = [] permutations = list(itertools.permutations(bag,x)) for item in permutations: possible_combos.append(" ".join(item))...

Python function to solve Ax = b by back substitution.

Okay, for my numerical methods class I have the following question: Write a Python function to solve Ax = b by back substitution, where A is an upper triangular nonsingular matrix. MATLAB code for this is on page 190 which you can use as a pseudocode guide if you wish. The function should take as input A and b and return x. Your functio...

Python: Advanced Nested List Comprehension Syntax

I was playing around with list comprehensions to get a better understanding of them and I ran into some unexpected output that I am not able to explain. I haven't found this question asked before, but if it /is/ a repeat question, I apologize. I was essentially trying to write a generator which generated generators. A simple generator t...

Python: binary tree traversal iterators without using conditionals

I am trying to create a module in python for iterating over a binary tree using the 4 standard tree traversals (inorder, preorder, postorder and levelorder) without using conditionals and only using polymorphic method dispatch or iterators. The following examples should work. for e in t.preorder(): print(e) for e in t.postorder(): ...

python validate text

I need to check that text contain only small letters a-z and , best way to do it in python? ...

Python Warning, possibly Numpy

As I run my code I get these warnings, allways in groups of four, sporadicly. I have tried to locate the source by placing debug messages before and after sertain statements to pin-point its origin. Warning: invalid value encountered in double_scalars Warning: invalid value encountered in double_scalars Warning: invalid value encountere...

Python: How to catch this kind of exception?

I'm making a program for AIX 5.3 in Python 2.6.1 that interfaces with an IMAP server. I'm getting an exception which I don't know how to catch - it doesn't seem to have a name that I can use with "except". The error seems to be some kind of timeout in the connection to the server. The last part of the stack trace looks like this: File ...

Namespaces in C# vs imports in Java and Python

In the Java and Python world, you look at a source file and know where all the imports come from (i.e. you know in which file the imported classes are defined). For example: In Java: import javafoo.Bar; public class MyClass { private Bar myBar = new Bar(); } You immediately see that the Bar-class is imported from javafoo. So, Ba...