python

Sorting music

So over the years, I've bought music off iTunes, Urge, and Rhapsody and all these files are lying mixed with my non-DRM'd MP3 files that I've ripped off my CDs. Now some of these files have licenses that have expired, and some of them have valid licenses. I want to sort my music by various DRM/license restrictions that they have on them...

How would I implement a Python bit map?

I wish to implement a 2d bit map class in Python. The class would have the following requirements: Allow the creating of arbitrarily sized 2d bitmaps. i.e. to create an 8 x 8 bitmap (8 bytes), something like: bitmap = Bitmap(8,8) provide an API to access the bits in this 2d map as boolean or even integer values, i.e.: if bitmap[1, 2...

Formatting a list of text into columns

I'm trying to output a list of string values into a 2 column format. The standard way of making a list of strings into "normal text" is by using the string.join method. However, it only takes 2 arguments so I can only make a single column using "\n". I thought trying to make a loop that would simply add a tab between columns would do it ...

Applying a common font scheme to multiple objects in wxPython

Many times I will use the same font scheme for static text in a wxPython application. Currently I am making a SetFont() call for each static text object but that seems like a lot of unnecessary work. However, the wxPython demo and wxPython In Action book don't discuss this. Is there a way to easily apply the same SetFont() method to all...

What is the best way to get all the divisors of a number?

Here's the very dumb way: def divisorGenerator(n): for i in xrange(1,n/2+1): if n%i == 0: yield i yield n The result I'd like to get is similar to this one, but I'd like a smarter algorithm (this one it's too much slow and dumb :-) I can find prime factors and their multiplicity fast enough. I've an generator that ge...

How do you organize Python modules?

When it comes to organizing python modules, my Mac OS X system is a mess. I've packages lying around everywhere on my hdd and no particular system to organize them. How do you keep everything manageable? ...

Which Python book would you recommend for a Linux Sysadmin?

Python for Unix and Linux System Administration is aimed at sysadmins. Any other favorites besides this. ...

How do you develop against OpenID locally

I'm developing a website (in Django) that uses OpenID to authenticate users. As I'm currently only running on my local machine I can't authenticate using one of the OpenID providers on the web. So I figure I need to run a local OpenID server that simply lets me type in a username and then passes that back to my main app. Does such an Op...

Django UserProfile... without a password

I'd like to create a subset of Users that don't have a login... basically as a way to add a photographer field to photos without having a full blown account associated with that person (since in many cases, they'll never actually log in to the site). A caveat is that I'd also like to be able to enable an account for them later. So, I th...

What are some good resources for learning data mining?

I'd like to get fluent enough in the data mining domain to be able to use the features of the Orange framework to classify photos of fish. ...

How are you planning on handling the migration to Python 3?

I'm sure this is a subject that's on most python developers' minds considering that Python 3 is coming out soon. Some questions to get us going in the right direction: Will you have a python 2 and python 3 version to be maintained concurrently or will you simply have a python 3 version once it's finished? Have you already started or p...

What symmetric cypher to use for encrypting messages?

I haven't a clue about encryption at all. But I need it. How? Say you have a system of nodes communicating with each other on a network via asynchronous messages. The nodes do not maintain session information about other nodes (this is a design restriction). Say you want to make sure only your nodes can read the messages being sent. I ...

How do I split a mult-line string into multiple lines?

I have a multi-line string literal that I want to do an operation on each line, like so. inputString = """Line 1 Line 2 Line 3""" I want to do something like the following. for line in inputString: doStuff() ...

What (pure) Python library to use for AES 256 encryption?

I am looking for a (preferably pure) python library to do AES 256 encryption and decryption. This library should support the CBC cipher mode and use PKCS7 padding according to the answer to an earlier question of mine. The library should at least work on Mac OS X (10.4) and Windows XP. Ideally just by dropping it into the source direct...

Speeding Up Python

This is really two questions, but they are so similar, and to keep it simple, I figured I'd just roll them together: Firstly: Given an established python project, what are some decent ways to speed it up beyond just plain in-code optimization? Secondly: When writing a program from scratch in python, what are some good ways to greatly ...

Parsing and generating Microsoft Office 2007 files (.docx, .xlsx, .pptx)

Hello, I have a web project where I must import text and images from a user-supplied document, and one of the possible formats is Microsoft Office 2007. There's also a need to generate documents in this format. The server runs CentOS 5.2 and has PHP/Perl/Python installed. I can execute local binaries and shell scripts if I must. We use...

Is there a way to prevent a SystemExit exception raised from sys.exit() from being caught?

The docs say that calling sys.exit() raises a SystemExit exception which can be caught in outer levels. I have a situation in which I want to definitively and unquestionably exit from inside a test case, however the unittest module catches SystemExit and prevents the exit. This is normally great, but the specific situation I am trying ...

python dictionary update method

I have a list string tag. I am trying to initialize a dictionary with the key as the tag string and values as the array index. for i, ithTag in enumerate(tag): tagDict.update(ithTag=i) The above returns me {'ithTag': 608} 608 is the 608th index My problem is that while the i is being interpreted as a variable, Python is treatin...

Does anyone have experience with PyS60 mobile development

I am in the position of having to make a technology choice early in a project which is targetted at mobile phones. I saw that there is a python derivative for S60 and wondered whether anyone could share experiences, good and bad, and suggest appropriate IDE's and emulators. Please don't tell me that I should be developing on Windows Mo...

Is it possible to pass arguments into event bindings?

I haven't found an answer elsewhere and this doesn't appear to have been asked yet on SO. When creating an event binding in wxPython, is it possible to pass additional arguments to the event? For example, this is the normal way: b = wx.Button(self, 10, "Default Button", (20, 20)) self.Bind(wx.EVT_BUTTON, self.OnClick, b) def On...