python

Django: queryset filter for *all* values from a ManyToManyField

Hi (sorry for my bad english :p) Imagine these models : class Fruit(models.Model): # ... class Basket(models.Model): fruits = models.ManyToManyField(Fruit) Now I would like to retrieve Basket instances related to all fruits. The problem is that the code bellow returns Basket instances related to any fruits : baskets = Baske...

ctypes memory management: how and when free the allocated resources?

I'm writing a small wrapper for a C library in Python with Ctypes, and I don't know if the structures allocated from Python will be automatically freed when they're out of scope. Example: from ctypes import * mylib = cdll.LoadLibrary("mylib.so") class MyPoint(Structure): _fields_ = [("x", c_int), ("y", c_int)] def foo(): p = ...

Is it possible to use django Piston on Google AppEngine?

I haven't been able to do so due to all sort of missing dependencies (mainly, I think the problem is in the authentication code which relies on django stuff that is not available on AppEngine) I was wondering if anyone patched\forked piston to get it working on AppEngine? ...

Most useful Python modules from the standard library?

I am teaching a graduate level Python class at the University of Paris, and the students need to be introduced to the standard library. I want to discuss with them about some of the most important standard modules. What modules do you think are absolute musts? Even though responses probably vary depending on your field (web programmin...

Python: Does a dict value pointer store its key?

I'm wondering if there is a built-in way to do this... Take this simple code for example: D = {'one': objectA(), 'two': objectB(), 'three': objectC()} object_a = D['one'] I believe object_a is just pointing at the objectA() created on the first line, and knows nothing about the dictionary D, but my question is, does Python store the K...

Allowing user to rollback from db audit trail with SQLAlchemy

I'm starting to use SQLAlchemy for a new project where I was planning to implement an audit trail similar to the one proposed on this quiestions: http://stackoverflow.com/questions/328898/implementing-audit-trail-for-objects-in-c http://stackoverflow.com/questions/315240/audit-trails-and-implementing-sox-hipaa-etc-best-practices-for-se...

Flow control in threading.Thread

I Have run into a few examples of managing threads with the threading module (using Python 2.6). What I am trying to understand is how is this example calling the "run" method and where. I do not see it anywhere. The ThreadUrl class gets instantiated in the main() function as "t" and this is where I would normally expect the code to sta...

How to define properties in __init__

I whish to define properties in a class from a member function. Below is some test code showing how I would like this to work. However I don't get the expected behaviour. class Basket(object): def __init__(self): # add all the properties for p in self.PropNames(): setattr(self, p, property(lambda : p) ) def PropNames...

What's a Django/Python solution for providing a one-time url for people to download files?

I'm looking for a way to sell someone a card at an event that will have a unique code that they will be able to use later in order to download a file (mp3, pdf, etc.) only one time and mask the true file location so a savvy person downloading the file won't be able to download the file more than once. It would be nice to host the file on...

How to set ignorecase flag for part of regular expression in Python?

Is it possible to implement in Python something like this simple one: #!/usr/bin/perl my $a = 'Use HELLO1 code'; if($a =~ /(?i:use)\s+([A-Z0-9]+)\s+(?i:code)/){ print "$1\n"; } Letters of token in the middle of string are always capital. Letters of the rest of words can have any case (USE, use, Use, CODE, code, Code and so on) ...

Python-based Gallery web applications?

I'm trying to cut my last dependencies on PHP and MySQL. The last stumbling block is a image gallery I set up for a client a while ago. The whole website is built around Django and Zine, except for the image gallery, which is based on plogger. I'd love to replace plogger with a Python solution. Requirements include: good admin interfac...

refer to map via. maps() action in python/ pylonshq

Hey I just started to learn python, and i'm totally new and n00b. Normally i work with php. I choose to use this framework: http://pylonshq.com/ I have created an map called ajax in my controller map. now i just need my "htaccees" file to find the ajax map. I want the file to go into the map /ajax/ where the file ajax_load.py is. ...

FFMPEG and Pythons subprocess.

I'm trying to write a gui for FFMPEG. I'm using pythons subprocess to create a ffmpeg process for every conversion I want. This works fine, but I'd also like a way to get the progress of the conversion, whether it failed or not etc. I figured I could do this by accessing the process's stdout like so: Calling subprocess.Popen() # Conver...

Python code does not work as expected when I run script as a Windows Service

Here is the code to get Desktop path on Windows Vista. import pythoncom import win32com.client pythoncom.CoInitialize() shell = win32com.client.Dispatch("WScript.Shell") desktop_path = shell.SpecialFolders("Desktop") Code works fine when I tried on python interpreter but its not working when I execute the same code from Python scrip...

Printing tuple with string formatting in Python

So, i have this problem. I got tuple (1,2,3) which i should print with string formatting. eg. tup = (1,2,3) print "this is a tuple %something" % (tup) and this should print tuple representation with brackets, like This is a tuple (1,2,3) How in the world am I able to do this? Kinda lost here so if you guys could point me to a right dir...

Could not get out of python loop ...

I want to get out of loop when there is no data but loop seems to be stopping at recvfrom image='' while 1: data,address=self.socket.recvfrom(512) if data is None:break image=image+data count=count+1 print str(count)+' packets received...' ...

How to build sqlite for Python 2.4?

I would like to use pysqlite interface between Python and sdlite database. I have already Python and SQLite on my computer. But I have troubles with installation of pysqlite. During the installation I get the following error message: error: command 'gcc' failed with exit status 1 As far as I understood the problems appears because ...

Can I "embed" a Python back-end in an AIR application?

I'm trying to find out if there is a way I could embed a Python back-end into an AIR application? I'm looking to employ an approach similar to the one outlined here to implement the business logic for my application, but additionally, I would like to provide the user with a single binary which they can load. I don't want the user to ha...

How to encrypt using public key?

msg = "this is msg to encrypt" pub_key = M2Crypto.RSA.load_pub_key('mykey.py') // This method is taking PEM file. encrypted = pub_key.public_encrypt(msg, M2Crypto.RSA.pkcs1_padding) Now I am trying to give file containing radix64 format public key as a parameter in this method and unable to get expected result i.e encryption using ra...

Can we run google app engine on ubuntu/windows and serve web application

I see google provide SDK and utilties to develop and run the web application in development (developer-pc) and port them to google app engine live (at google server). Can we use google app engine to run the local web application without using google infrastructure? Basically I want a decent job scheduler and persistent job queue for p...