python

active object in python for s60

Hi, How do I use active object in python for s60? can anybody give me a code example? ...

Run a terminal command and saving the values returned using Python/Django?

Hi all, I have a question regarding the use of Python. How do i run a command line command using Python? And after running the command, how do i save the returned values? For example: user@home:~$: ls -l drwxr-xr-x 3 root root 4096 ..[etc] home -rw-r--r-- 1 user user 357 ..[etc] examples.doc So what i intend to do, is to run the co...

django models filter() and extra()

Hi all, I have a problem with the extra() method of queryset. So, i retrieve my objects with : invoices = Invoice.objects.select_related().filter(quantity__gt=0,begin__gte=values['start_day'],end__lte=values['end_day']) So it works, I have my invoices. After i use another time filter() : invoices = invoices.filter(max__gte=duration...

Pythonic way to intercept calls to a function?

For testing things that query the environment (e.g., os.getenv, sys.version, etc.), it's often more convenient to make the queries lie than to actually fake up the environment. Here's a context manager that does this for one os.getenv call at a time: from __future__ import with_statement from contextlib import contextmanager import os ...

Using DirectShow in Python

I'd like to call this method inside a Python script, with as few extra dependencies as possible. How can I do it? I've tried DirectPython, but it's installer installs only for 32-bit architectures, it seems. I've tried comtypes, but the installer can't find my Python installation. ...

Python error - psycopg2: no appropriate 64-bit architecture?!

I'm running Mac OSX. Until today I had Python 2.6 with psycopg2 running just fine, I was using it with Django and Pylons. I've just reintalled postgres (I don't know if this is connected) and suddenly I can't import psycopg2 into Python without a strange error: >>> import psycopg2 Traceback (most recent call last): File "<stdin>", li...

Alternative ways to instantiate a class in Python

I am currently writing my python classes and instantiate them like this class calculations_class(): def calculate(self): return True Calculations = calculations_class() I was wondering if I was doing this correctly, or if there were any other ways to instantiate them. Thanks! ...

How can one find Class of calling function in python?

I am trying to determine the owning class of a calling function in python. For example, I have two classes, ClassA and ClassB. I want to know when classb_instance.call_class_a_method() is the caller of class_a.class_a_method() such that: class ClassA(object): def class_a_method(self): # Some unknown process would occur here...

Mercurial: Permission Denied for hgwebdir

Yesterday I setup Apache to serve my Mercurial repositories and got everything working properly. I then tested pushing changes back to this repository and was presented with an error, and now that error pops up for every single operation I attempt - even just a simple GET request of the repositories! Here is the error: mod_wsgi (pid=177...

TypeError: unbound method __init__() .... during unit tests after re-packaging

I've just repackaged my program. Previously all modules lived under the "whyteboard" package, with a "fakewidgets" package containing a bunch of dummy GUI test objects. Now, all my modules are in packages, e.g. whyteboard.gui, whyteboard.misc, whyteboard.test - which is where fakewidgets now lives. Now, when running my tests, I get an ...

How to get first top five objects with django.views.generic.date_based.archive_index?

Hello, I'm trying to display the latest 5 posts using a generic view like this: urlpatterns = patterns('', (r'^$', 'django.views.generic.date_based.archive_index', { 'queryset': Post.objects.all()[:5], 'date_field': 'created_on', 'template_name': 'index.html'} }) However I am getting AssertionError at...

Pythonic way to assign an instance of a subclass to a variable when a specific string is presented to the constructor of the parent class.

I want to be able to create an instance of a parent class X, with a string "Q" as an extra argument. This string is to be a name being an identifier for a subclass Q of the parent class X. I want the instance of the parent class to become (or be replaced with) an instance of the subclass. I am aware that this is probably a classic pro...

Python daemonize

Hi, I would like to daemonize a python process, and now want to ask if it is good practice to have a daemon running, like a parent process and call another class which opens 10-30 threads. I'm planning on writing a monitoring script for group of servers and would like to check every server every 5 mins, that each server is checked ex...

How to extend distutils with a simple pre uninstall script?

I found Question#1321270 for post install. My main target for the moment is bdist_wininst, but i did not find anything related to uninstall... For clarification: I want to register a com server after installation and de-register it before uninstall. Extended answer: ars' answer seems correct, however, for the completeness of things (I ...

how to log error to file, and not fail on exception

I am downloading a file from the net, and it fails even though I am doing: for p in query: try: except IOError as e: print e; If there is an error, I want to log it, and then continue on with the next file. In this loop, I am trying to download an image, if for some reason the filename was bad, or the website was down, etc., I w...

Is it possible to detect duplicate image files?

I have over 10K files for products, the problem is is that many of the images are duplicates. If there is no image, there is a standard image that says 'no image'. How can I detect if the image is this standard 'no image' image file? Update The image is a different name, but it is exactly the same image otherwise. People are saying H...

Gae db.model @property setters and getters

How can I use properties in db.models that are not meant to be handled as datastore properties? For instance: class SpotModel(db.Model): rating = db.RatingProperty(default=3, choices=[1,2,3,4]) @smiley.setter def smiley(self, value): return value In the above I have a property called smiley, but when I test it using nosete...

os.execv without args argument

Hey, I want to replace the current process with a new one using os.execv, this works fine unless you don't have any arguments. How can I call this even if I don't have an arguments to pass to the process I want to launch ? # Works fine, unless the arguments tuple wouldn't exist or be empty os.execv('process.exe', ('arg1', 'arg2')) ...

Learning Python; How can I make this more Pythonic?

I am a PHP developer exploring the outside world. I have decided to start learning Python. The below script is my first attempt at porting a PHP script to Python. Its job is to take tweets from a Redis store. The tweets are coming from Twitter's Streaming API and stored as JSON objects. Then the information needed is extracted and dumpe...

How to bundle a Gnome applet with distutils?

I'm trying to write a Gnome applet in Python. In fact, I've written the app and I'm stuck when it comes to packaging it. I started by looking into distutils. The problem I ran into right away was that when specifying py_modules, an extension of .py is expected. However, Gnome applets are basically shell scripts. (That use the Python int...