python

"Better option" from the python library, any list?

I just found out the existence of the optparse module. I personally always used getopt, so I did not care to look for something better. It's clear, however, that optparse is much more advanced, so I would expect it to be the preferred way in the future to get options from the command line. Anyway, this event struck me. I am now wonderin...

With sqlalchemy how to dynamically bind to database engine on a per-request basis

I have a Pylons-based web application which connects via Sqlalchemy (v0.5) to a Postgres database. For security, rather than follow the typical pattern of simple web apps (as seen in just about all tutorials), I'm not using a generic Postgres user (e.g. "webapp") but am requiring that users enter their own Postgres userid and password, ...

Django - Populating a database for test purposes.

I need to populate my database with a bunch of dummy entries (around 200+) so that I can test the admin interface I've made and I was wondering if there was a better way to do it. I spent the better part of my day yesterday trying to fill it in by hand (i.e by wrapping stuff like this my_model(title="asdfasdf", field2="laksdj"...) in a b...

Questionnaire/survey app like Google Form - (python+javascript)

Django-survey or django-questionnaire is too admin-centric for me (beside tied to django). I want my user to create their own survey. Something like Google Form survey (view example), where form creation feels fluid and intuitive (because of js magic). I've googling around with no luck. Is there any python-based survey app/library/pack...

sparse assignment list in python

I need a list with the following behavior >>> l = SparseList() >>> l [] >>> l[2] = "hello" >>> l [ None, None, "hello"] >>> l[5] None >>> l[4] = 22 >>> l [ None, None, "hello", None, 22] >>> len(l) 5 >>> for i in l: print i None None "hello" None 22 Although it can "emulated" via a dictionary, it's not exactly the same. numpy array ca...

Python proxy checker, change to threaded version

Hello ALL, i have some python proxy checker. and to speed up check, i was decided change to multithreaded version, and thread module is first for me, i was tried several times to convert to thread version and look for many info, but it not so much easy for novice python programmer. if anyone can help me really much appreciate!! th...

How to extract every possible values of python Dict's values to list

DICTA={'bw':['BW','VW'],'b':['BB','VV'],'a':['AA']} DICTB={'yn':['$YN','$YNN'],'ye':['$YE','A$Y'],'y':['Y$']} How to extract every possible values of that 2 Dict to ["BWYN","VWYN","BBYN","VVYN","AAYN","BWYNN","VWYNN","BBYNN","VVYNN","AAYNN", "BWYE","VWYE","BBYE","VVYE","AAYE","ABWY","AVWY","ABBY","AVVY","AAAY", "YBW","YVW","YBB","YVV"...

Flexible numeric string parsing in Python

Are there any Python libraries that help parse and validate numeric strings beyond what is supported by the built-in float() function? For example, in addition to simple numbers (1234.56) and scientific notation (3.2e15), I would like to be able to parse formats like: Numbers with commas: 2,147,483,647 Named large numbers: 5.5 billion ...

Bind different ip addresses to urllib2 object in seperate threads

The following code binds specified ip address to socket in main program globally. import socket true_socket = socket.socket def bound_socket(*a, **k): sock = true_socket(*a, **k) sock.bind((sourceIP, 0)) return sock socket.socket = bound_socket Suppose main program has 10 threads, each with a urllib2 instance running insid...

Python Source Formatter

I am building a Python application and I have a class with a lot of functions (more than 20). I'm developing it using Eclipse with PyDev. While the general interface is good, I have the problem of managing the placement of functions. I need to add/delete or change the placement of functions in the source to group similar functions togeth...

What is a library that provides a very simple, universal usage of Naives Bayes classifier?

I know that NLTK has this. But...is that only for NLP? Is there a library that specializes in classification? ...

How to pass items as args lists in map?

This is a piece of my code. Lambda accepts 3 parameters, and I wanted to pass them as a tuple of positional arguments, but apparently map supplies them as a single argument. How can I supply those tuples in the bottom as lists of arguments? (I know I can rewrite the lambda, but it will become not well readable) adds = map((lambda j, f...

Creating portable Django apps - help needed.

I'm building a Django app, which I comfortably run (test :)) on a Ubuntu Linux host. I would like to package the app without source code and distribute it to another production machine. Ideally the app could be run by ./runapp command which starts a CherryPy server that runs the python/django code. I've discovered several ways of doing ...

Check if key is pressed using python (a daemon in the background)

I've created a python script in which an event needs to be executed each time I press the Super (or WinKey) on my keyboard. How can one achieve this without the python process being "focused" - as it is running in the background waiting for the key to be pressed to execute the event? I've seen a lot of posts around the web showing me h...

Python: Continuing to next iteration in outer loop

Hi, I wanted to know if there are any built-in ways to continue to next iteration in outer loop in python. For example, consider the code: for ii in range(200): for jj in range(200, 400): ...block0... if something: continue ...block1... I want this continue statement to exit the jj loop and goto ...

Pygame sprite transformation with interpolation

Im currently working on a Python/Pygame module to wrap some basic sprite animation. Animation in the sense that the image itself is static but I apply rotation and scale with start and end values with a sine wave interpolation. That is, sprite transformation like the ones that could be made in Flash. I hope you understand, otherwise feel...

problem with pyglet playing video

hello . I'm new to pyglet and i have a problem with video.. I'm trying to play a video using pyglet .. but instead of playing the video in the window it just exits immediately and terminates .. do you guys have any solution for this problem how can i hold the window to play vedio?? i use windows vista 64x with python 2.5 please help ...

Is there a buildout recipe that uses pip but does not install virtualenv?

I would like to use buildout rather than virtualenv. This decision means that I don't want virtualenv to be snuck into my kit, so I am looking for either a way to tell gp.recipe.pip not to install the virtualenv meme virus, or, a way to install packages from git repos for use with django/djangorecipe. Ideas? ...

Using Python, how do I get a binary serialization of my Google protobuf message?

I see the function SerializeAsString in the protobuf Python documentation, but like this suggests, this gives me a string version of the binary data. Is there a way of serializing and parsing a binary array of protobuf data using Python? We have a C++ application that stores the protobuf messages as binary data in a file. We'd like to r...

Using AppEngine XMPP for Client Notifications

I've been looking for a way to tell clients about expired objects and AppEngine's XMPP implementation seems really interesting because it's scalable, should be reliable and can contain up to 100kb of data. But as I understand it, before a client can listen to messages, he should have a gmail account. That's very impractical. Is there ...