python

how can i limit my django foreign key selection by a property stored in the django session

i have a small application i am implementing with django and i'm having a slight challenge. I'm trying to limit the queryset for my relationships within my application by a particular property. Now the catch is, the exact value of the property isn't known until the user logs into the application. an example is limiting a set of comments ...

implementing callback between Python and C

I have wrapped some C code using SWIG to use it as a python library. Within this framework, some python code I have written calls a C function, which returns a string. However, for creating the string, the C function requires a ranking, the generation of which I have implemented in Python. How would I go about implementing this using ca...

Python and Postgres on Red Hat

I've been having trouble installing psycopg2 on linux. I receive the following error when I try to import psycopg2. Python 2.6.4 (r264:75706, Nov 19 2009, 14:52:22) [GCC 3.4.6 20060404 (Red Hat 3.4.6-3)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import psycopg2 Traceback (most recent call last...

Django Celery causes an import error on runserver command

When I issue a runserver command, an ImportError is raised from djcelery (Django Celery). % python manage.py runserver ~/Workspace/django-projects/no-labels/src Validating models... Unhandled exception in thread started by <functi...

python middleware to capture errors?

is there a python middleware that captures errors from web app and emails it? which is the easiest one to use. i am deploying app using nginx proxying to multiple app servers of gunicorn+web.py framework. right now any error is printed out in each app server, which is not very easy to manage. what is the best way to handle this? ...

Testing call order across mock objects with Mox and Python

Hi, I'm testing a function that obtains a skeleton object from one helper object, modifies it using a second helper, and passes the modified object back to the first helper. Something along the lines of: class ReadModifyUpdate(object): def __init__(self, store, modifier): self._store = store self._modifier = modifie...

Python: Where is freeze.py?

Anyone know where freeze.py is installed for 2.6.5? I can't seem to find it anywhere. Did it get pulled out and replaced with something else? ...

Using the video-card memory (ram) to store objects.

Is it possible to store objects in the video-card memory instead of the ram? I have been using StringIO to store some objects in the RAM; would it be possible to allocate some of the video-card's memory for this purpose? ...

catching a broken socket in python

I'm having problems detecting a broken socket when a broken pipe exception occurs. See the below code for an example: The Server: import errno, select, socket, time, SocketServer class MetaServer(object): def __init__(self): self.server = Server(None, Handler, bind_and_activate=False) def run(self, sock, addr): ...

tkFileDialog.askopenfilename How to specify a different drive?

I'm using "tkFileDialog.askopenfilename" to get a file name variable. I know that I can set the "initialdir" option, but not everyone who uses the program will have the target file on the same drive. For example: the file could be located on the C:, D:, E: etc... I don't see a way to view available drives with the dialog box they have op...

How can I add a command to the Python interactive shell?

I'm trying to save myself just a few keystrokes for a command I type fairly regularly in Python. In my python startup script, I define a function called load which is similar to import, but adds some functionality. It takes a single string: def load(s): # Do some stuff return something In order to call this function I have to ty...

Problems creating tables one to one relation

Hello, I get errors when I try to create tables one to one relation. Screen contains crm and crm contains more classes. The relation is one to one between crm, so I want to use the screen id as primary key in crm. And the relation is one to one between crm and some classes, I just added one class as example, so children of crm must cont...

How can I make an alias to a non-function member attribute in a Python class?

I'm in the midst of writing a Python Library API and I often run into the scenario where my users want multiple different names for the same functions and variables. If I have a Python class with the function foo() and I want to make an alias to it called bar(), that's super easy: class Dummy(object): def __init__(self): pass...

Once I can save this string as image, other time I can'

Ok. Long story short. My camera has a method which takes a photo and this is what it returns: [160, 120, 3, 10, 1287848024, 96181, 'super long image string'] I am able to decode the string and save it as image right after I call the method like this: for i in range(0, 10): image = camProxy.getImageRemote(nameId) imageWidth = ima...

How can we modify data that is in a shelve?

I have opened a shelve using the following code: #!/usr/bin/python import shelve #Module:Shelve is imported to achieve persistence Accounts = 0 Victor = {'Name':'Victor Hughes','Email':'[email protected]','Deposit':65000,'Accno':'SA456178','Acctype':'Savings'} Beverly = {'Name':'Beverly Dsilva','Email':'[email protected]...

Implement a Web based Client that interacts with a TCP Server.

EDIT:Question Updated. Thanks Slott. I have a TCP Server in Python. It is a server with asynchronous behaviour. . The message format is Binary Data. Currently I have a python client that interacts with the code. What I want to be able to do eventually implement a Web based Front End to this client. I just wanted to know , what ...

How do I add a shapefile in ArcGIS via python scripting?

I am trying to automate various tasks in ArcGIS Desktop (using ArcMap generally) with Python, and I keep needing a way to add a shape file to the current map. (And then do stuff to it, but that's another story). The best I can do so far is to add a layer file to the current map, using the following ("addLayer" is a layer file object): ...

Passing a list of values to a function

Sorry for such a silly question, but sitting in front of the comp for many hours makes my head overheated, in other words — I'm totally confused. My task is to define a function that takes a list of words and returns something. How can I define a function that will take a list of words? def function(list_of_words): do something ...

convert string to datetime object

I'd like to convert this string into a datetime object: Wed Oct 20 16:35:44 +0000 2010 Is there a simple way to do this? Or do I have to write a RE to parse the elements, convert Oct to 10 and so forth? EDIT: strptime is great. However, with datetime.strptime(date_str, "%a %b %d %H:%M:%S %z %Y") I get ValueError: 'z' is a bad d...

Python: Is it bad style to give an argument the same name as the function?

Consider the following code: def localize(value, localize=None): # do something with the localize argument The localize variable contains information whether the global localization setting should be respected or not. It is called by the same name through three layers of code. What's the lesser evil, shadow the function name wi...