python

Is it possible to save a list of values into a SQLite column?

I want 3 columns to have 9 different values, like a list in Python. Is it possible? If not in SQLite, then on another database engine? ...

Python Image Library ellipse with wide outline

When creating an ellipse with PIL, is it possible to have a thicker/wider outline? Currently, I'm trying to do canvas.ellipse(box, outline=colour, fill=None), but would like to be able to give the outline parameter a width. ...

Using lookahead with generators

Hi all, I have implemented a generator-based scanner in Python that tokenizes a string into tuples of the form (token type, token value): for token in scan("a(b)"): print token would print ("literal", "a") ("l_paren", "(") ... The next task implies parsing the token stream and for that, I need be able to look one item ahead fr...

What's the best way to read python documentation for all installed packages?

I use python.org a lot for reading python documentation. I also use ipython help function, but I would prefer a GUI app that I could run on my machine that would show documentation for all installed packages. Do you know if anything like this exists? Do you have any suggestions? ...

Python Image Uploading with AjaxUpload

I'm trying to use AjaxUpload with Python: http://valums.com/ajax-upload/ I would like to know how to access the uploaded file with Python. On the web site, it says: * PHP: $_FILES['userfile'] * Rails: params[:userfile] What is the Syntax for Python? request.params['userfile'] doesn't seem to work. Thanks in advance! Here is my c...

banshee: How would I set the rating for a specific track on Banshee through DBus?

I'd like to set the 'rating' of a specific track (i.e. not only the one currently playing) on Banshee through the DBus interface? ...

How to keep query parameters during pagination with webhelpers.paginate

I look an example of paginating from http://rapidprototype.ch/bg2docs/tg2pagination.html for my Turbogears 2 project and it works great but, I have a problem regarding my query parameters when I change the page I'm looking. This is what I have in my controller when listing. def list(self, page=1, **kw): q = "" if kw.has_key('q...

Django - use reverse url mapping in settings

A few of the options in the django settings file are urls, for example LOGIN_URL and LOGIN_REDIRECT_URL. Is it possible to avoid hardcoding these urls, and instead use reverse url mapping? At the moment this is really the only place where I find myself writing the same urls in multiple places. ...

Using Embedded Dictionary for iterative charater replacement

I'm trying to understand an iterative function that that takes a string "12345" and returns all the possible misspellings based upon a dictionary of keys close to each character in the string. outerDic = {} Dict1 = {'1':'2','2':'q'} outerDic['1'] = Dict1 Dict1 = {'1':'1','2':'q','3':'w','4':'3'} outerDic['2'] = Dict1 Dict1 = {'1':'2','2...

Python - Google App Engine

Hi, I'm just starting learning google app engine. When I enter the following code below, all I got is "Hello world!" I think the desired result is "Hello, webapp World!" What am I missing? I even try copying the google framework folder to live in the same folder as my app. Thanks. from google.appengine.ext import webapp from google.a...

How to parse Youtube search results?

When a user submits a query, I would like to append this to search results in Youtube and download this "page" on the backend of my code (Python-Django). What is the best way to do this? Do you suggest that I do this manually? And create a custom parser? Scanning each line for a certain pattern... Or is there an easier way, such as us...

Stripping code for production

So I want to physically get rid of debugging code before deploying it to appengine. What I'm doing right now is a simple check: settings.py: DEBUG = os.environ['HTTP_HOST'] == 'localhost' from settings import DEBUG if DEBUG: #ensure I haven't screwed smth up during refactoring But this check will be consuming CPU cycles during ea...

Python most common element in a list

What is an efficient way to find the most common element in a Python list? My list items may not be hashable so can't use a dictionary. Also in case of draws the item with the lowest index should be returned. Example: >>> most_common(['duck', 'duck', 'goose']) 'duck' >>> most_common(['goose', 'duck', 'duck', 'goose']) 'goose' ...

Snow Leopard Python 2.6 problems getting PIL to work

I installed libjpeg and PIL, but when I try to save a JPG image, I always get this error: ImportError: The _imaging C module is not installed Any help much appreciated! I tried to import _imaging w/ Python interpreter to see what's wrong and got this: >>> import _imaging Traceback (most recent call last): File "<stdin>", line 1...

Python and indentation, having touble getting started.

I have just started learning python and am getting caught up. I come from mostly C background. class Alarm: def timer(): def main(): print ("Timer has Started") main() I always get a silly error when I try to run this code:: alarm > python alarm.py File "alarm.py", line 5 def main(): ^ IndentationEr...

How can I detect when a flash drive is plugged in under Linux?

Hello, How can I detect when a flash drive is plugged in? I'm using a bare Debian installation, without any GUI and want to be notified in my Python script when a new flash drive appears... I know that D-BUS distributes such information, but i dont want to use D-BUS. Is there a more bare access to that information? Shouldn't that be ava...

Need help in designing a phone book application on python running on google app engine

Hi I want some help in building a Phone book application on python and put it on google app engine. I am running a huge db of 2 million user lists and their contacts in phonebook. I want to upload all that data from my servers directly onto the google servers and then use a UI to retrieve the phone book contacts of each user based on his...

How to install numpy and scipy on Windows XP

I have a problem installing Numpy and Scipy from http://www.scipy.org/Installing%5FSciPy/Windows I went to download page and downloaded .exe files for Python26. I have Python26 on my machine. After installation, I tried >>> import nympy, scipy Traceback (most recent call last): File "<stdin>", line 1, in <module> ImportError: No modu...

Combine two lists: aggregate values that have similar keys

I have two lists or more than . Some thing like this: listX = [('A', 1, 10), ('B', 2, 20), ('C', 3, 30), ('D', 4, 30)] listY = [('a', 5, 50), ('b', 4, 40), ('c', 3, 30), ('d', 1, 20), ('A', 6, 60), ('D', 7, 70]) i want to get the result that move the duplicate elements like this: my result is to get all the list from listX +...

In managed code, how do I achieve good locality of reference?

Since RAM seems to be the new disk, and since that statement also means that access to memory is now considered slow similarly to how disk access has always been, I do want to maximize locality of reference in memory for high performance applications. For example, in a sorted index, I want adjacent values to be close (unlike say, in a ha...