python

what's a good module for writing an http web service interface for a daemon?

To give a little background, I'm writing (or am going to write) a daemon in Python for scheduling tasks to run at user-specified dates. The scheduler daemon also needs to have a JSON-based HTTP web service interface (buzzword mania, I know) for adding tasks to the queue and monitoring the scheduler's status. The interface needs to receiv...

Faster Deserialization in Python

What do you think is the fastest deserialization method? Pickle? YAML? or JSONPickle? ...

distributing independent python app to other machines

I created independent python app using cxfreeze under linux and can run it other machines without python and other dependencies. But while doing it for mac OS X, in other machines the app searches for the following python installed location which actually present in the machine where it is frozen. "/Library/Frameworks/Python.framework...

How to get the point in time of (last) vertical retrace under Python?

Hi there, I am using Pygame to pageflip different stimuli on the screen. The problem is that pygame's flip function, although syncing the flip to the vertical retrace, does not tell me when the retrace was. Does anyone know of a way to get this information (preferably platform independent) in Python? Regards, fladd ...

Django: Saving an image file from a form

I want to save the image which as been uploaded via the PaletteGenForm as such: #Form class PaletteGenForm(forms.Form): im = forms.ImageField(required=True) #View def palette_gen_view(request): PATH_OF_IMAGE_TO_BE_PALETTED= MEDIA_ROOT+ "/tobesaved.png" if request.method == 'POST': form = PaletteGenForm(request.POST...

Kick off deamonized service using djangos manage.py custom command?

I got a custom command in my reusable django app which I want to kick off a deamonized service and then return, leaving the service running. I've implemented my service as a simple class with a start-method. When start is called it runs in an eternal loop, sleeping for 10 seconds, then using the django orm to check the database configur...

BeautifulSoup get innerhtml data

I am trying to read data from a website. I can see the value I need but the value does not appear in the downloaded html code (using urllib2). The value is created by some js file and embedded into the webpage as innerhtml for that id. PS: How can that be extracted? raw source code cannot render js unlike the browsers! ...

python import error no module named

Dear All, Hello, I am very new at python. I have an existing example project that have some scripts YYY,in path XXX/YYY and an script A.py that call these one by one, I only want to add an script ZZZ.py to the YYY scripts so that call after them. I add this scrit in the same path (XXX/ZZZ.py) and try to import it in the A.py and call it....

merging 2 columns in a csv file through python

Possible Duplicate: to merge two columns in a csv file i need to take 2 different columns in the csv file... say col[4] and col[13]... i want to merge the data in these 2 columns into a single column (and i need to insert a dot between these 2 strings) and then copy it to a different csv file.... how do i implement this in pyt...

Python converting the values from dicts into a tuples

I have a list of dictionaries that looks like this: [{'id':1,'name':'Foo'},{'id':2,'name':'Bar'}] I'd like to convert the values from each dict into a list of tuples like this: [(1,'Foo'),(2,'Bar')] How can I do this? ...

Django - Selecting related set : how many times does it hit the database ?

I took this sample code here : http://stackoverflow.com/questions/853184/django-orm-selecting-related-set polls = Poll.objects.filter(category='foo') choices = Choice.objects.filter(poll__in=polls) My question is very simple : do you hit twice the database when you finally use the queryset choices ? ...

How to validate XML file against DTD/XMLSchema using lxml.etree.iterparse()

lxml easily validates XML files against any DTD or XMLSchema if only you're using etree.XML(). I need to do the same trick with etree.iterparse(), so that whole XML file won't be put into memory. There are two problems here: 1. DTD is ignored by iterparse (be it internal or external) 2. XML is validated against XMLSchema, but errors ...

What's the best way to store quickly-changing data in Python?

On a quest to learn a bit about Python and sockets I'm writing a little 2d-game server. And although I don't see more than a few people on this server at any given time, I want to write it as efficiently as I can. I have a global dictionary called "globuser", in it is another dictionary containing the user stats (like the X & Y coordin...

Psycopg2 callproc and sql parameters

I got some SQL function CREATE OR REPLACE FUNCTION tools.update_company(IN company_id integer, OUT value integer) RETURNS integer AS $BODY$ BEGIN select * into value from function_making_int(company_id) END;$BODY$ and from Psycopg2 (its inside Django if that matters) I do c = connection.cursor() c.callproc('tools.update_compa...

Pyttsx not saying all text when using non default voice

I created a small module to speak the text that is sent to it. It works fine if I don't use engine.setProperty to set the voice, but if I set the voice it will only play the first command. import pyttsx def speak( text ): if text != "": engine = pyttsx.init() engine.setProperty('voice', "HKEY_LOCAL_MACHINE\SOFTWARE...

Good practices for a flexible search page - Django

Hi folks, I'm just wondering if there is any example I could take from others on the topic. I have a page within Django which uses filters, in order to perform searches. At the moment I'm doing a simple check for the GET parameters and adding a .filter() to a queryset accordingly: if color: query.filter(color=color) This feels ...

Unit Testing / Eclipse / Command Line

I have project with the following layout (Python 2.4.3) root +--- src +--- xyz +--- __init__.py +--- C1.py +--- C2.py +--- test +--- xyz +--- __init__.py +--- CXMock.py +--- C1Test.py +--- C2Test.py So i'm writing a un...

Precentage chance to make action

Simple problem: precentage_chance = 0.36 if <don't know what>: #action here has 36% chance to execute pass How can i solve this problem? ...

How to debug Python code that is partially covered by passing unit tests but produces wrong results when being reused?

I have a Python class and its methods are partially covered by unit tests like this: class MyClass: def __init__(self): self.instancevar1 = None # some methods change this value self.instancevar2 = None # some methods change this value ... def method1(self, input_data): ... <self.instance...

Images are not being stored?? - Django

Hi folks, These are my following settings: MEDIA_ROOT = '/home/webapps/test_project/media/' MEDIA_URL = 'http://192.168.0.2:8090/site_media/' ADMIN_MEDIA_PREFIX = '/media/' These are my model fields: large = models.ImageField(blank=True, null=True, upload_to="images") thumb = models.ImageField(blank=True, null=True, upload_to="image...