python

Python calling pipe.communicate() in a thread

Using Python 2.6.1 on Mac OS X 10.6.2, I've the following problem: I have a threaded process (a Thread class), and each of those threads has a pipe (a subprocess.Popen) something likeso: from threading import Thread cmd = "some_cmd" class Worker(Thread): def run(self): pipe = Popen(cmd, stdin=PIPE, stdou...

Find elements based on xsd type with lxml

I am trying to get a list of elements with a specific xsd type with lxml 2.x and I can't figure out how to traverse the xsd for specific types. Example of schema: <xsd:element name="ServerOwner" type="srvrs:string90" minOccurs="0"> <xsd:element name="HostName" type="srvrs:string35" minOccurs="0"> Example xml data: <srvrs:ServerOwner...

Python-daemon doesn't kill its kids

When using python-daemon, I'm creating subprocesses likeso: import multiprocessing class Worker(multiprocessing.Process): def __init__(self, queue): self.queue = queue # we wait for things from this in Worker.run() ... q = multiprocessing.Queue() with daemon.DaemonContext(): for i in xrange(3): Worker(q) ...

In python, what is the fastest way to determine if a string is an email or an integer?

I'd like to be able to pull users from a database using either a supplied e-mail address or the user id (an integer). To do this, I have to detect if the supplied string is an integer, or an e-mail. Looking for the fastest way to do this. Thanks. def __init__(self, data): #populate class data self._fetchInfo(data) def _fetc...

No matter what I do, django-admin.py is not found, even though it's in my path

I have added C:\Python26\Lib\site-packages\django\bin to my path, I have started a new cmd session in Windows 7, but when I try to do 'python django-admin.py ...' it says there is no file django-admin.py. When I type path, there is the full path to ...\django\bin. This is driving me nuts. Clearly it's there, but it's not working. Any su...

Is it possible to write an IM server in python? (be able to handle the heavy connections)

Hi all, i wanna write an IM server in python, but i'm not sure if python can handle the heavy connections? Thanks in advance. ...

Class Decorators, Inheritance, super(), and maximum recursion

I'm trying to figure out how to use decorators on subclasses that use super(). Since my class decorator creates another subclass a decorated class seems to prevent the use of super() when it changes the className passed to super(className, self). Below is an example: def class_decorator(cls): class _DecoratedClass(cls): def ...

How do you determine which file is imported in Python with an "import" statement?

How do you determine which file is imported in Python with an "import" statement? I want to determine that I am loading the correct version of a locally modified .py file. Basically the equivalent of "which" in a POSIX environment. ...

What is the most efficient way to populate class attributes with a row from a database query?

Looking to have a database query set all the instance variables in a class: Example: def populate(self, if): #Perform mysql query self._name = row['name'] self._email = row['email'] ... What's the fastest way to do this? Or is this not recommended (with a better approach)? Thanks. ...

What python libraries can tell me approximate location and timezone given an IP address?

Looking to implement better geo-location with Python. Thanks. ...

python on 32 bit

Hi I am running Windows XP, on 32bit. How do I install python? When I run the installation file, it gives me an error saying "installation package not supported by processor type" does python need 64 bit to execute? ...

Pylons: Set global variable for Authkit user

How can I can set a global variable for the username of the logged-in user? At the moment i have the following code in all my controllers to get the username. I rather set it as a global variable if possible. request.environ.get("REMOTE_USER") I tried putting the same code in the app_globals.py file but it gave me the following error m...

How to call Twiter's Streaming/Filter Feed with urllib2/httplib?

Update: I switched this back from answered as I tried the solution posed in cogent Nick's answer and switched to Google's urlfetch: logging.debug("starting urlfetch for http://%s%s" % (self.host, self.url)) result = urlfetch.fetch("http://%s%s" % (self.host, self.url), payload=self.body, method="POST", headers=self.headers, allow_trun...

Do you know any Augmented Reality library for python?

I would like to code something with augmented reality, do you know any python library to play with? ...

change the colour of a product in an image

Hi, I want to change the colour of a product in an image. for example http://www.momgoesgreen.com/wp-content//ikea-blue-bags.jpg. I want to change the colour of the product to anything i like for example to black, red or brown using python . Please give a sample code Thanks ...

Django Distinct on queryset in forms.py

Hi all, I try to get a list with distinct into the forms.py like this: forms.ModelMultipleChoiceField(queryset=Events.objects.values('hostname'), required=False).distinct() In the python shell this command works perfect, but when trying it in forms.py leaves me a blank form, so nothing appears. When i just do Events.objects.all() the ...

"No module named slimmer.middleware"

Hello guys, I'm trying to setup blog engine django-mingus, but meet this obstacle: [Tue Mar 30 04:14:02 2010] [error] [client 192.168.12.161] mod_wsgi (pid=12908): Exception occurred processing WSGI script '/home/piv/srv/python-env/myblog/project/django-mingus/mingus/deploy/django.wsgi'. [Tue Mar 30 04:14:02 2010] [error] [client 192.16...

python: what are efficient techniques to deal with deeply nested data in a flexible manner?

My question is not about a specific code snippet but more general, so please bear with me: How should I organize the data I'm analyzing, and which tools should I use to manage it? I'm using python and numpy to analyse data. Because the python documentation indicates that dictionaries are very optimized in python, and also due to the f...

Overwrite the Soap Envelope in Suds python

Hello, I have a camera and I am trying to connect to it vis suds. I have tried to send raw xml and have found that the only thing stopping the xml suds from working is an incorrect Soap envelope namespace. The envelope namespace is: xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" and I want to rewrite it to: xmlns:SOAP-EN...

wxPython, Threads, and PostEvent between modules

I'm relatively new to wxPython (but not Python itself), so forgive me if I've missed something here. I'm writing a GUI application, which at a very basic level consists of "Start" and "Stop" buttons that start and stop a thread. This thread is an infinite loop, which only ends when the thread is stopped. The loop generates messages, whi...