python

Google App Engine: 403 and 404 error

How do I implement using python if I want to manage the 403 and 404 error, for example, to know which URL is most the 403 or 404 error? ...

Whats the best way to extend Anonymous User in Django?

I want to make my User objects all have the same base behaviour and to do so I need to add a couple of methods / properties to Anonymous User. I've already subclassed User to make richer user objects but I was wondering if anyone has done the same for Anonymous User? And if there are any preferred ways of doing it! ...

Problems with sys.stdout.write() with time.sleep() in a function

What I wanted is printing out 5 dots that a dot printed per a second using time.sleep(), but the result was 5 dots were printed at once after 5 seconds delay. Tried both print and sys.stdout.write, same result. Thanks for any advices. import time import sys def wait_for(n): """Wait for {n} seconds. {n} should be an integer great...

Installing Python egg dependencies without apt-get

I've got a Python module which is distributed on PyPI, and therefore installable using easy_install. It depends on lxml, which in turn depends on libxslt1-dev. I'm unable to install libxslt1-dev with easy_install, so it doesn't work to put it in install_requires. Is there any way I can get setuptools to install it instead of resorting to...

How to show raw_id value of a ManyToMany relation in the Django admin?

Hello, I have an app using raw_id on both ForeignKeyField and ManyToManyField. The admin displays the value of the foreign key on the right of the edit box. Unfortunatey, it doesn't work with ManyToMany. I've checked the code and I think that it is the normal behavior. However I would like to know if someone has an easy tip to change t...

Are there any Bayeux clients in Python?

I need to connect to a Bayeux server form a wxPython APP. I would appreciate any hint about that. ...

Sleeping a thread is blocking stdin

Hey, I'm running a function which evaluates commands passed in using stdin and another function which runs a bunch of jobs. I need to make the latter function sleep at regular intervals but that seems to be blocking the stdin. Any advice on how to resolve this would be appreciated. The source code for the functions is def runJobs(comp...

How to run own python script in Trac

Hi All, I want to customize the project page (trac/templates/index.html). I want to use a table to show more project-specific information. For instance the admin list of each project, the build status of each project. These information are stored in trac's database. I am afraid that the default template engine is not able to give me ...

can i just broadcast a specific message in my own network in python

i just want to broadcast a udp message on a specific port in my network, so how can i broadcast a message in python? ...

sort a list of percentages

I have the following list: l = ['50%','12.5%','6.25%','25%'] Which I would like to sort in the following order: ['6.25%','12.5%','25%','50%'] Using l.sort() yields: ['12.5%','25%','50%','6.25%'] Any cool tricks to sort these lists easily in Python? ...

Writing csv header removes data from numpy array written below

I'm trying to export data to a csv file. It should contain a header (from datastack) and restacked arrays with my data (from datastack). One line in datastack has the same length as dataset. The code below works but it removes parts of the first line from datastack. Any ideas why that could be? s = ','.join(itertools.chain(dataset)) + ...

Reverse Engineer a .pyo python file

I have 2 .pyo python files that I can convert to .py source files, but they don't compile perfectly as hinted by decompyle's verify. Therefore looking at the source code, I can tell that config.pyo simply had variables in in an array: ADMIN_USERIDS = [116901, 141, 349244, 39, 1159488] I would like to take the original .pyo and di...

Which button was clicked?

How can I detect which mouse button was clicked (right or left) in the slot for QtCore.SIGNAL('cellClicked(int,int)')? ...

Can I get the raw SQL generated by a prepared statement in Python’s sqlite3 module?

If so, how can I do this? ...

python socket problem

I write this python code: import socks import socket socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS5, "64.83.219.7", 58279) socket.socket = socks.socksocket socket.setdefaulttimeout(19) import urllib2 print urllib2.urlopen('http://www.google.com').read() but when I execute it, I get this error: urllib2.URLError: <urlopen error timed ou...

Sqlalchemy+elixir: How query with a ManyToMany relationship?

Hi, I'm using sqlalchemy with Elixir and have some troubles trying to make a query.. I have 2 entities, Customer and CustomerList, with a many to many relationship. customer_lists_customers_table = Table('customer_lists_customers', metadata, Column('id', Integer, primary_key=True), ...

Making a CharField use a PasswordInput in the admin

I have a Django site in which the site admin inputs their Twitter Username/Password in order to use the Twitter API. The Model is set up like this: class TwitterUser(models.Model): screen_name = models.CharField(max_length=100) password = models.CharField(max_length=255) def __unicode__(self): return self.screen_name I need the A...

Model Django Poll

I am working through the Django tutorials, and now I am at creating a poll. The code below works fine until I want to create choices, where for some reason I always get this error message: line 22, in __unicode__ return self.question AttributeError: 'Choice' object has no attribute 'question' What am I doing wrong? Here's my code...

Python file input string: how to handle escaped unicode characters?

In a text file (test.txt), my string looks like this: Gro\u00DFbritannien Reading it, python escapes the backslash: >>> file = open('test.txt', 'r') >>> input = file.readline() >>> input 'Gro\\u00DFbritannien' How can I have this interpreted as unicode? decode() and unicode() won't do the job. The following code writes Gro\u00DFbr...

Embedding Python and adding C functions to the interpreter

I'm currently writing an applications that embedds the python interpreter. The idea is to have the program call user specified scripts on certain events in the program. I managed this part but now I want the scripts to be able to call functions in my program. Here's my code so far: #include "python.h" static PyObject* myTest(PyObject...