python

Efficient way to use python's lambda, map

I need to store a big list of integers in Bigtable(db). For efficiency I am storing them as diff between 2 consecutive items. for eg: original_list = [1005, 1004, 1003, 1004, 1006] Storing the above list(which actually contains more than 1000k items) as start = 1005 diff = [-1, -1, 1, 2] The closest I could manage is, ltp = [st...

appengine: NeedIndexError: The built-in indices are not efficient enough for this query and your data. Please add a composite index for this query.

While using django.core.paginator import ObjectPaginator, I'm getting this error: NeedIndexError: The built-in indices are not efficient enough for this query and your data. Please add a composite index for this query. The original query is written in this form: query = models.Cdr.all() query.filter("var1 =", var1 ) query.fi...

python DST and GMT management into a scheduler

I'm planning to write a sheduler app in python and I wouldn't be in trouble with DST and GMT handling. As example see also PHP related question 563053. Does anyone worked already on something similar? Does anyone already experienced with PyTZ - Python Time Zone Library? ...

Python singleton / object instantiation

Hi, I'm learning Python and i've been trying to implement a Singleton-type class as a test. The code i have is as follows: _Singleton__instance = None class Singleton: def __init__(self): global __instance if __instance == None: self.name = "The one" __instance = self else...

[Embedded Python] Invoking a method on an object

Given a PyObject* pointing to a python object, how do I invoke one of the object methods? The documentation never gives an example of this: PyObject* obj = .... PyObject* args = Py_BuildValue("(s)", "An arg"); PyObject* method = PyWHATGOESHERE(obj, "foo"); PyObject* ret = PyWHATGOESHERE(obj, method, args); if (!ret) { // check error....

Stopping python using ctrl+c

I have a python script that uses threads and makes lots of HTTP requests. I think what's happening is that while a HTTP request (using urllib2) is reading, it's blocking and not responding to ctrl+c to stop the program. Is there any way around this? ...

Python 3.1 inline division override

I don't know if this is a bug in 3.1, but if I remember correctly "inline" division worked like this in pre-3k versions: Python 3.1 (r31:73574, Jun 26 2009, 20:21:35) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> class A: ... def __init__(self, x): ... sel...

Python generating Python

Ok, I have a group of objects which I am creating a class for that I want to store each object as its own text file. I would really like to store it as a Python class definition which subclasses the main class I am creating. So, I did some poking around and found a Python Code Generator on effbot.org. I did some experimenting with it and...

Block requests from *.appspot.com and force custom domain in Google App Engine

How can I prevent a user from accessing my app at example.appspot.com and force them to access it at example.com? I already have example.com working, but I don't want users to be able to access the appspot domain. I'm using python. ...

How to connect to a GObject signal in python, without it keeping a reference to the connecter?

The problem is basically this, in python's gobject and gtk bindings. Assume we have a class that binds to a signal when constructed: class ClipboardMonitor (object): def __init__(self): clip = gtk.clipboard_get(gtk.gdk.SELECTION_CLIPBOARD) clip.connect("owner-change", self._clipboard_changed) The problem is now that, no inst...

Python on Snow Leopard, how to open >255 sockets?

Consider this code: import socket store = [] scount = 0 while True: scount+=1 print "Creating socket %d" % (scount) s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) store.append(s) Gives the following result: Creating socket 1 Creating socket 2 ... Creating socket 253 Creating socket 254 Traceback (most recent ca...

Python packages depending on libxml2 and libxslt

Apart from lxml, is anyone aware of Python packages that depend on libxml2 and libxslt? ...

virtualenv in PowerShell?

Hi fellow pythonistas, there seems to be a problem when virtualenv is used in PowerShell. When I try to activate my environment in PowerShell like.. > env/scripts/activate .. nothing happens. (the shell prompt should have changed as well as the PATH env. variable .) I guess the problem is that PowerShell spawns a new cmd. process jus...

Is storing user configuration settings on database OK?

I'm building a fairly large enterprise application made in python that on its first version will require network connection. I've been thinking in keeping some user settings stored on the database, instead of a file in the users home folder. Some of the advantages I've thought of are: the user can change computers keeping all its set...

How to deal with user authentication and wrongful modification in scripting languages?

I'm building a centralized desktop application using Python/wxPython. One of the requirements is User authentication, which I'm trying to implement using LDAP (although this is not mandatory). Users of the system will be mechanical and electrical engineers making budgets, and the biggest problem would be industrial espionage. Its a comm...

On localhost, how to pick a free port number?

Hello, I try to play with inter process communication and since I could not figure out how to use named pipes under Windows I thought I'll use network sockets. Everything happens locally, server is able to launch slaves in a separate process and listens on some port and the slaves do their work and submit the result to the master. How do...

What's a server equivalent of django.test.client to test external URL fetch?

I'd like to make sure a given view in my test is fetching an external URL properly. It uses urllib2 (but this shouldn't matter, since it's blackbox testing). Perhaps a temporary local server of some kind? Is there an app that does this already? (My Googling has failed me.) ...

Center Google Map Based on geocoded IP

Basically whenever someones opens up my (Google) map I want it default to their approximate location. Is there an easy way to do it with Google's API or do I have to write a custom code (this is python based app)? ...

Managing multiple Twisted client connections

I'm trying to use Twisted in a sort of spidering program that manages multiple client connections. I'd like to maintain of a pool of about 5 clients working at one time. The functionality of each client is to connect to a specified IRC server that it gets from a list, enter a specific channel, and then save the list of the users in tha...

Python long filename support broken in Windows

Hi, I write Python script to copy files; unfortunately it keeps failing because filename is too long(>256). Is there anyway to deal with that problem? I'm using Python 2.5.4 and Windows XP. Cheers, ...