PyMOTW: optparse

The optparse module is a modern alternative for command line
option parsing that offers several features not available in getopt,
including type conversion, option callbacks, and automatic help
generation. There are many more features for to optparse than can be
covered here, but hopefully this introduction will get you started if
you are writing a command line program soon.

Read more at pymotw.com: optparse

feedcache 1.1

There is a new release of feedcache available tonight, based on a
patch from Thomas Perl. The update includes Unicode support for URLs, a
“force” flag to always download data, and an “offline” mode flag to
never download data.

Thanks, Thomas!

Python Developer Networking

Jesse Noller is leading a campaign to have Python developers form a
network via LinkedIn.com. He talks about it over on his blog, so
check it out for the details.

According to Doug Napoleone‘s comment on Jesse’s post, there is a
more formal effort to set up a PyCon08 group and tie it in with the web
site for the convention. I didn’t realize that LinkedIn supported
groups other than “employers”. It looks like the right way to go for
the community is a “networking group” (there are only a few types, and
the others seem to imply a more formal organization than what we would
have). Unfortunately, the groups feature is closed for right now.

For now, following Jesse’s lead, I set up a position with the “Python
community” organization and job title “None”. I had to guess at the
start date. :-)

I noticed several Python-oriented groups over on Facebook, so that
might be an alternative if LinkedIn doesn’t come through. Somehow
LinkedIn feels more professional; maybe I just have a historical bias
based on Facebook’s origins, though.

PyMOTW: csv

The csv module is very useful for working with data exported from
spreadsheets and databases into text files. There is no well-defined
standard, so the csv module uses “dialects” to support parsing using
different parameters. Along with a generic reader and writer, the module
includes a dialect for working with Microsoft Excel.

Read more at pymotw.com: csv

PyMOTW: getopt

The getopt module is the old-school command line option parser which
supports the conventions established by the Unix function getopt().
It parses an argument sequence, such as sys.argv and returns a
sequence of (option, argument) pairs and a sequence of non-option
arguments.

Read more at pymotw.com: getopt

feedcache 1.0

I am happy with the API for feedcache, so I bumped the release to 1.0
and beta status. The package includes tests and 2 separate examples (one
with shelve and another using threads and shove).

CommandLineApp

Back when Python 1.5.4 was hot and new, I wrote a class to serve as a
basis for the many command line programs I was working on for myself and
my employer. This was long before the Option Parsing Wars that resulted
in the addition of optparse to the standard library. If optparse had
been around, I probably wouldn’t have written CommandLineApp, but
since all I had to work with at the time was getopt, and it operated at
such a low level, I hacked together a helper class.

The difference between CommandLineApp and optparse is that
CommandLineApp treats your application as an object, just like
everything else in the application. The application class is responsible
for option processing, although it collaborates with getopt to do the
parsing work.

To use it, you subclass CommandLineApp and define option handler
methods and a main(). To invoke the program, call run(). The option
handlers are identified by name, and used to build the list of supported
options. optionHandler_myopt() is called when –myopt is encountered.
If the method takes an argument, so does your option. The docstrings for
the callback methods are used to create the help output. Support for
short-form usage (via -h) and long-form help (via –help) are built-in
to the base class.

The old version (released as 1.0), which had not received a
substantial rewrite in many years (mostly because it still worked fine
and I had more important projects to work on) can run under Python 1.4
through 2.5. It was some of the earliest complex Python code I ever
wrote, and that is clear from the code quality (both style and
substance). The new version has been tested under Python 2.5. It feels
less hack-ish, since it uses inspect instead of scanning the class
hierarchy and method signatures directly.

The 2.0 rewrite works in essentially the same way as 1.0, but is much
more compact and (I think) the code is cleaner. I called it 2.0 because
the class API is different in a few important ways from the earlier
version. I still want to add argument validation (for non-option
arguments to the program), but that will take a little more time.

ORM envy

Jonathan LaCour presented an overview of SQLAlchemy at last night’s
PyATL meeting, and now I have ORM envy. It’s too bad I can’t afford the
effort that would be involved in replacing the in-house ORM we use at
work, but I’ll definitely consider using it for my own projects.

PyMOTW: shelve

The shelve module can be used as a simple persistent storage option
for Python objects when a relational database is overkill. The shelf is
accessed by keys, just as with a dictionary. The values are pickled and
written to a database created and managed by anydbm.

Read more at pymotw.com: shelve