python

Filter and sort music info on Google App Engine

I've enjoyed building out a couple simple applications on the GAE, but now I'm stumped about how to architect a music collection organizer on the app engine. In brief, I can't figure out how to filter on multiple properties while sorting on another. Let's assume the core model is an Album that contains several properties, including: ...

IS there a good non- GPL python libraries for finding the length of an mp3?

I have found a few libraries that are under GPL but are there any under BSD? or any other non-GPL license? ...

Remove ppc from compilation flags in python setup scripts

I'm trying to install PIL on an Intel Mac OS X Leopard machine. Unfortunately, "setup.py build" thinks it should be compiling for ppc. gcc -arch ppc -arch i386 -isysroot /Developer/SDKs/MacOSX10.4u.sdk -fno-strict-aliasing -Wno-long-double -no-cpp-precomp -mno-fused-madd -fno-common -dynamic -DNDEBUG -g -O3 -DHAVE_LIBJPEG -DHAVE_LIBZ -...

Django transaction.commit_on_success not rolling back transaction

I'm trying to use Django transactions on MySQL with the commit_on_success decorator. According to the documentation, "If the function raises an exception, though, Django will roll back the transaction." However, this doesn't seem to work for me: >>> @transaction.commit_on_success ... def fails(): ... Site.objects.create(name="New ...

Multiple periodic timers

Is there any standard python module for creating multiple periodic timers. I want to design a system which supports creating multiple periodic timers of different periodicity running in just one thread. The system should be able to cancel a specific timer at any point of time. Thanks in advance for any input! ...

Basic Python dictionary question

I have a dictionary with one key and two values and I want to set each value to a separate variable. d= {'key' : ('value1, value2'), 'key2' : ('value3, value4'), 'key3' : ('value5, value6')} I tried d[key][0] in the hope it would return "value1" but instead it return "v" Any suggestions? ...

Allowing the " - " character in usernames in the Django Admin interface.

In our webapp we needed to allow dashes "-" in our usernames. I've enabled that for the consumer signup process just fine with this regex r'^[\w-]+$' How can I tell the admin app so that I can edit usernames in auth > users to allows the "-" character in usernames? Currently I am unable to edit any usernames with dashes in them as it...

How to get environment from a subprocess in Python

I want to call a process via a python program, however, this process need some specific environment variables that are set by another process. How can I get the first process environment variables to pass them to the second? This is what the program look like: import subprocess subprocess.call(['proc1']) # this set env. variables for ...

XSLT Transform of Unicode source

In my application I am using the 4Suite.org XSLT library to perform transformations of source XML. The syntax is like this: from Ft.Xml.Xslt import Transform transformed_xml = Transform(raw_xml, stylesheet) where raw_xml and stylesheet have been defined elsewhere in my application. raw_xml will be the xml resulting from reading a fi...

Counting and filtering objects in a database with Django

I'm struggling a little to work out how to follow the relation and count fields of objects. In my Django site, I have a profile model: user = models.ForeignKey(User, unique=True) name = models.CharField(_('name'), null=True, blank=True) about = models.TextField(_('about'), null=True, blank=True) location = models.CharField(_('location'...

Filtering dictionaries and creating sub-dictionaries based on keys/values in Python?

Ok, I'm stuck, need some help from here on... If I've got a main dictionary like this: data = [ {"key1": "value1", "key2": "value2", "key1": "value3"}, {"key1": "value4", "key2": "value5", "key1": "value6"}, {"key1": "value1", "key2": "value8", "key1": "value9"} ] Now, I need to go through that dictionary already to format some o...

oauth google using python

i am fairly new to programming for web. and i want to start from scratch here. i tried to search the net but ended up completely confused. now what i want to learn is how to authenticate a google account through a python script. can anyone please provide me with a code fragment or any example. thanks a lot in advance. ...

How might I remove duplicate lines from a file?

I have a file with one column. How to delete repeated lines in a file? ...

Where can I find useful documentation for pyusb (Python USB library)?

I am trying to interact with a keyboard with pyusb but I can't find any documentation or tutorial for it. The project homepage has absolutely no information and the installed README file is pretty useless. There is no man page. I found mailing lists but the people there have way more advanced problems than me. The only useful thing I fo...

How to list all class properties

I have class SomeClass with properties. For example id and name: class SomeClass(object): def __init__(self): self.__id = None self.__name = None def get_id(self): return self.__id def set_id(self, value): self.__id = value def get_name(self): return self.__name def set_nam...

Can a Python function take a generator and return generators to subsets of its generated output?

Let's say I have a generator function like this: import random def big_gen(): i = 0 group = 'a' while group != 'd': i += 1 yield (group, i) if random.random() < 0.20: group = chr(ord(group) + 1) Example output might be: ('a', 1), ('a', 2), ('a', 3), ('a', 4), ('a', 5), ('a', 6), ('a', 7), ('a', 8), ('b', 9), ('...

Ubuntu + virtualenv = a mess? virtualenv hates dist-packages, wants site-packages

Can someone please explain to me what is going on with python in ubuntu 9.04? I'm trying to spin up virtualenv, and the --no-site-packages flag seems to do nothing with ubuntu. I installed virtualenv 1.3.3 with easy_install (which I've upgraded to setuptools 0.6c9) and everything seems to be installed to /usr/local/lib/python2.6/dist-pa...

Search engine woes

I have been trying to make this search engine for a MySQL database. Taking in user input is no problem, database querying is also fine. One thing I need to figure out is this: I am a string in the database How do I match the input "AM", but keep the same case? There are PHP functions like str_ireplace or preg_replace/eregi_replace...

Removing (or prefilling) the address details for PayPal Express Checkout

I am looking at using PayPal as a payment option for my custom shopping cart I have built. I already have a cart set up, and a checkout 'complete'. It asks the user for their address. Once they have completed all the fields, they hit 'Pay with PayPal'. This does not send them to PayPal yet. First it processes the data they entered, THEN ...

import serial error occured in Python

I wrote import serial There message are occured. Traceback (most recent call last): File "<stdin>", line 1, in ? File "/usr/lib/python2.4/site-packages/serial/__init__.py", line 20, in ? from serialposix import * File "/usr/lib/python2.4/site-packages/serial/serialposix.py", line 13, in ? import sys, os, fcntl, termios,...