python

Python's time.sleep - never waking up

I think this is going to be one of those simple-when-you-see-it problems, but it has got me baffled. [STOP PRESS: I was right. Solution was found. See the answers.] I am using Python's unittest framework to test a multi-threaded app. Nice and straight forward - I have 5 or so worker threads monitoring a common queue, and a single produ...

Python's c api and __add__ calls

I am writing a binding system that exposes classes and functions to python in a slightly unusual way. Normally one would create a python type and provide a list of functions that represent the methods of that type, and then allow python to use its generic tp_getattro function to select the right one. For reasons I wont go into here, I ca...

Ordering of Django models

I set up an ordering='ordering_number' Meta attribute to my Django model, thinking that Django will use it when comparing instances. (ordering_number is an IntegerField in my model.) For example, if I have an instance a with ordering_number = 4 and an instance b with ordering_number = 7, I'd expect that a < b would be True. However, I t...

How to add an Admin class to a model after syncdb?

I added some models in my models.py and I want to add an admin class to use a wysiwyg-editor in text-fields. Well, I know that Django itself doesn't support migrations and I've used South, but it doesn't work either. South doesn't "see" the change. Could...

How to build an image object in PIL/Python

I have a list of 3-item tuples that is the result of list(PIL.Image.getdata()). How do I do the opposite: build a PIL.Image object from this list? ...

py2exe error (importErorr:DLL load failed :The specified module could not be found)

when i compile a python application with py2exe i get the bellow error: Traceback (most recent call last): File "myapp.pyw", line 2, in File "pymssql.pyc", line 30, in File "_mssql.pyc", line 12, in File "_mssql.pyc", line 10, in __load ImportError: DLL load failed: The specified module could not be found. here are the setup.py...

django admin.site.name in template

Hallo, is there any chance to access the "name" value of the current admin.site object in a admin template? I have 3 different admin.site-objects and want a template tag to generate generic content,depending on the current admin.site.name. thanks in advance ...

Python sub-package references

I am about at wits end with what should be an extremely simple issue. Here is the format of a simple example that I wrote to try to fix my problem. I have a folder top with __all__ = ["p1","p2"] in __init__.py . I then have sub-folders p1 and p2 with __init__.py in both of them with __all__ again defined with the names of two simple modu...

Is there any Python wrapper around cron ?

I'm looking for a wrapper around cron. I've stumbled upon PyCron but it's a Python implementation, not a wrapper. Do you know any good cron Python wrapper ? If not, did you test PyCron, and what can you tell about it ? //EDIT (As an answer to comment asking for more details): I am looking for something to set a cron job in a pythoni...

Easiest way to serialize a simple class object with simplejson?

I'm trying to serialize a list of python objects with JSON (using simplejson) and am getting the error that the object "is not JSON serializable". The class is a simple class having fields that are only integers, strings, and floats, and inherits similar fields from one parent superclass, e.g.: class ParentClass: def __init__(self, ...

Writing to file doesn't flush content automatically and cause out of memory in Python

Hi, I made simple python program to generate big text file: import sys import random f = open('data.txt', 'w') for i in range(100000000): f.write(str(i) + "\t" + str(random.randint(0,1000)) + "\n") f.close() When I launch it using CPython it eat all available OS memory and write nothing to the file. When I launch it on Jyth...

Python module for Tomcat 5.5 manager

Is there any python module for managing remotely running tomcat 5.5 server? Or, could you help me to write python script for deploying local .war file on remote tomcat server? ...

NLP project, python or C++

We are working on Arabic Natural Language Processing project, we have limited our choices to either write the code in Python or C++ (and Boost library). We are thinking of these points: Python Slower than C++ (There is ongoing work to make Python faster) Better UTF8 support Faster in writing tests and trying different algorithms C++...

Python Regex to match a file in a list of files (getting error)

I'm trying to use a regex in Python to match a file (saved as a string, ie "/volumes/footage/foo/bar.mov") to a log file I create that contains a list of files. But when I run the script, it gives me this error: sre_constants.error: unbalanced parenthesis. The code I'm using is this: To read the file: theLogFile = The_Root_Path + ".pro...

Python script is running. I have a method name as a string. How do I call this method?

Hi, everyone. Please see example below. I'd like to supply a string to 'schedule_action' method which specifies, what Bot-class method should be called. In the example below I've represented it as 'bot.action()' but I have no idea how to do it correctly. Please help class Bot: def work(self): pass def fight(self): pass class Sc...

pylint: Using possibly undefined loop variable 'n'

Pylint say W: 6: Using possibly undefined loop variable 'n' with this code: iterator = (i*i for i in range(100) if i % 3 == 0) for n, i in enumerate(iterator): do_something(i) print n because if the iterator is empty (for example []) n is undefined, ok. But I like this trick. How to use it in a safe way? I think that usin...

pysqlite, query for duplicate entries with swapped columns

Currently I have a pysqlite db that I am using to store a list of road conditions. The source this list is generated from however is buggy and sometimes generates duplicates. Some of these duplicates will have the start and end points swapped but everything else the same. The method i currently have looks like this: def getDupes(self)...

Python: group results by time intervals

I have a large data loaded from a pickled file. The data is a sorted list of tuples containing a datetime and an int like this [ (datetime.datetime(2010, 2, 26, 12, 8, 17), 5594813L), (datetime.datetime(2010, 2, 26, 12, 7, 31), 5594810L), (datetime.datetime(2010, 2, 26, 12, 6, 4) , 5594807L), etc ] I want to get a population ...

Minimize python distribution size

The hindrance we have to ship python is the large size of the standard library. Is there a minimal python distribution or an easy way to pick and choose what we want from the standard library? The platform is linux. ...

PyUnit tearDown and setUp vs __init__ and __del__

Is there a difference between using tearDown and setUp versus init and del when using the pyUnit testing framework? If so, what is it exactly and what is the preferred method of use? Thanks. ...