python

Google App Engine Python Unit Tests

Hi, I'd like to write some Python unit tests for my Google App Engine. How can I set that up? Does someone happen to have some sample code which shows how to write a simple test? ...

Enthought Python, Sage, or others (in Unix clusters)

I have access to a cluster of Unix machines, but they don't have the software I need (numpy, scipy, matplotlib, etc), so I have to install them by myself (I don't have root permissions, either, so commands like apt-get or yast don't work). In the worst case, I will have to compile them all from source. Is there any better way to proceed...

Sending Data as Instances using Python Sockets

I'm working on the networking part of a 2 player game (similar to tetris), and I'm trying to pass the game grid from client to server and vice versa. However, when I tried using send(grid) I get a TypeError: send() argument 1 must be string or read-only buffer, not instance. Is there anyway to circumvent this, or do I have to convert m...

Representing geographical points/polygons in Python/Django

I'm building a website in Django, and I want one of my datatypes to be a geographical polygon. I want to mark points on a map (say, in Google Maps) and then store the resulting polygon in the database. Is there any way to do it that will save me the work of typing all the longitudes and latitudes manually? I guess I'm looking both for...

Which version of Python should be used?

I'm starting a new Python web project. With most frameworks, everyone rushes to the latest version, however, it seems that this is not as true for Python 3.x. Which version of Python should brand new projects use? ...

How do I check for Existence of a Record in GAE

I am trying to create a simple view in Django & GAE, which will check if the user has a profile entity and prints a different message for each case. I have the program below, but somehow GAE always seem to return a object. My program is below import datetime from django.http import HttpResponse, HttpResponseRedirect from google.appengi...

module compiled with swig not found by python

Hello, I've a problem with SWIG and python. I've a c-class that compiles correctly, but the python script says it can't find the module. I compile with: swig -c++ -python codes/codes.i g++ -c -Wall -O4 -fPIC -pedantic codes/*.cc g++ -I/usr/include/python2.6 -shared codes/codes_wrap.cxx *.o -o _codes.so This gives me a _codes.so file...

In Python, is there an easy way to edit xml in place ?

Suppose I want to edit a node in xml and edit one of its attributes. I want to be able to do a simple file diff to just see one row changed. Dumping the xml using prettyprint changes the whole xml structure. ...

Figure out if element is present in multi-dimensional array in python

I am parsing a log containing nicknames and hostnames. I want to end up with an array that contains the hostname and the latest used nickname. I have the following code, which only creates a list over the hostnames: hostnames = [] # while(parsing): # nick = nick_on_current_line # host = host_on_current_line if host in hostname...

Validity of GUI design patterns under linux

I am investigating a switch from windows to linux and i struggle to find samples of design patterns applied in this world. The application is a classic client server with detailed forms for each business entity. It will be taking user input, do some validation checks, a few calculations, and save them to database. It will also have list...

Make qwidget in new window in PyQt4

I'm trying to make a class that extends qwidget, that pops up a new window, I must be missing something fundamental, class NewQuery(QtGui.QWidget): def __init__(self, parent): QtGui.QMainWindow.__init__(self,parent) self.setWindowTitle('Add New Query') grid = QtGui.QGridLayout() label = QtGui.QLabel('blah') grid.addWidget(la...

Reduce function calls

Hello, I profiled my python program and found that the following function was taking too long to run. Perhaps, I can use a different algorithm and make it run faster. However, I have read that I can also possibly increase the speed by reducing function calls, especially when it gets called repeatedly within a loop. I am a python newbie ...

chatbot using twisted and wokkel

I am writing a chatbot using Twisted and wokkel and everything seems to be working except that bot periodically logs off. To temporarily fix that I set presence to available on every connection initialized. Does anyone know how to prevent going offline? (I assume if i keep sending available presence every minute or so bot wont go offline...

Getting a RichTextCtrl's default font size in wxPython

I have a RichTextCtrl, which I've modified to accept HTML input. The HTML parsing code needs to be able to increase and decrease the font size as it gets tags like <font size="-1">, but I can't work out how to get the control's default font size to adjust. I tried the following (where self is my RichTextCtrl): fred = wx.richtext.RichTex...

Python fCGI + sqlAlchemy = malformed header from script. Bad header=FROM tags : index.py

I'm writing an Fast-CGI application that makes use of sqlAlchemy & MySQL for persistent data storage. I have no problem connecting to the DB and setting up ORM (so that tables get mapped to classes); I can even add data to tables (in memory). But, as soon as I query the DB (and push any changes from memory to storage) I get a 500 Int...

Appengine (python) returns empty for valid queries

EDIT: Figured it out. For whatever reason the field in the index was called strWord instead of wordStr. I didn't notice because of the similarities. The file was auto generated, so I must have called the field that in a previous development version. I've got an app with around half a million 'records', each of which only stores three fi...

Algorithm detect repeating/similiar strings in a corpus of data -- say email subjects, in Python

I'm downloading a long list of my email subject lines , with the intent of finding email lists that I was a member of years ago, and would want to purge them from my Gmail account (which is getting pretty slow.) I'm specifically thinking of newsletters that often come from the same address, and repeat the product/service/group's name in...

I need to authenticate against one db with python and openfire. How do I do this?

Its not urgent but I was just wondering how one would go about authenticating against a single db using python and openfire? Is there a simple module that will do this? ...

Python questions from beginner

I'm thinking about rewriting an MS Access db I wrote years ago into a stand-alone Python app. Other than a college class called "Intro to C++" (console only, with OOP concepts) and the Access db itself, I have no experience, so I need to ask if the basis for my decision to go with Python is correct. Is it true that: 1) Python is relat...

Python grab class in class definition.

I don't even know how to explain this, so here is the code I'm trying. from couchdb.schema import Document, TextField class Base(Document): type = TextField(default=self.__name__) #self doesn't work, how do I get a reference to Base? class User(Base): pass #User.type be defined as TextField(default="Test2") The reason...