PyMOTW: glob

Even though the glob API is very simple, the module packs a lot of power. It is useful in any situation where your program needs to look for a list of files on the filesystem with names matching a pattern. If you need a list of filenames that all have a certain extension, prefix, or any common string in the middle, use glob instead of writing code to scan the directory contents yourself.

PyMOTW: calendar

The calendar module defines the Calendar class, which encapsulates calculations for values such as the dates of the weeks in a given month or year. In addition, the TextCalendar and HTMLCalendar classes can produce pre-formatted output. Read more at calendar

Converting podcasts to regular tracks in iTunes

I have spent the better part of the morning trying to work out how to convert podcasts to “regular” tracks in iTunes, so they would show up in shuffle, etc. Mostly this was for my collection of Jonathan Coulton “Thing a Week” episodes, but it would be useful for anything you wanted to move out of your podcast list into the main audio portion of the library. I suppose the reason it took so long to find the solution is I started by searching for it on Google instead of just looking through the iTunes menu options, though as you will see the solution wasn’t immediately obvious even once I had found it.

Unexpectedly broken, and fixed: svnbackup

Yesterday Pierre Lemay sent me one of the clearest bug reports I’ve seen in quite a while, and a patch to fix the problem. He was having trouble with svnbackup duplicating changesets in the dump files. It turns out every changeset that appeared on a “boundary” (at the end of one dump file and the beginning of the next) was included in both dumps. Oops. When I tested the script, I was able to recover the repository without any trouble.

PyMOTW: getpass

Many programs which interact with the user via the terminal need to ask the user for password values without showing what the user types on the screen. The getpass module provides a portable way to handle such password prompts securely. Read more at getpass

Unexpectedly popular: svnbackup

My svnbackup script is the second most popular page on my site, after the PyMOTW home page, and search terms such as “svn backup” and “svn backup script” regularly appear at the top of the list of sources of traffic to my site. The link to svnbackup doesn’t appear on the first page of Google’s search results, a sign I take to mean that this problem isn’t well understood or solved (otherwise, why would so many people page through the search results to find it?

PyMOTW: atexit

The atexit module provides a simple interface to register functions to be called when a program closes down normally. The sys module also provides a hook, sys.exitfunc, but only one function can be registered there. The atexit registry can be used by multiple modules and libraries simultaneously. Read more at atexit

PyMOTW: subprocess

The subprocess module provides a consistent interface to creating and working with additional processes. It offers a higher-level interface than some of the other available modules, and is intended to replace functions such as os.system, os.spawn*, os.popen*, popen2.* and commands.*. To make it easier to compare subprocess with those other modules, this week I will re-create earlier examples using the functions being replaced. Read more at subprocess

PyMOTW: pickle and cPickle

The pickle module implements an algorithm for turning an arbitrary Python object into a series of bytes (“serializing” the object). The byte stream can then be transmitted or stored, and later reconstructed to create a new object with the same characteristics. The cPickle module implements the same algorithm, in C instead of Python. It is many times faster than the Python implementation, but does not allow the user to subclass from Pickle.

DjangoKit help?

I spent a little time last night trying to assemble an application using DjangoKit without much success. I’m running Python 2.5 on a PowerBook with Mac OS 10.4. I downloaded and installed PyObjC from source so it would compile (I thought) against the right version of Python, then installed DjangoKit using python install. Everything seemed to be working, and I was able to build an application. But when I ran that app, it produced an error about the version of the SQLite libraries being used (2 instead of 3) and missing libraries.