Sunday, 28 March 2004

BlogMatrix Jäger

I finally got David Janes’ new feedreader working under Windows XP (the previous 0.4.something release just seemed to hang, but 0.5.01 works fine). It’s a pretty slick tool, although there are a few minor quibbles I’d make:

  • It doesn’t seem to discover Atom feeds, which seems odd. (I’m not sure if it supports Atom or not—that may explain why it doesn’t discover Atom feeds.)
  • The “Political Righties” blogroll (InstaPundit, Lileks, Marginal Revolution, Samizdata, Volokh) seems, well, not to have any real righties in it, at least when compared with the “Lefties” blogroll (Calpundit, Crooked Timber, Eschaton/Atrios, Matt Welch, TalkLeft, and This Modern World/Tom Tomorrow). Maybe that’s a Canuck thing.
  • Signifying Nothing isn’t included in the default blogroll anywhere. (Just kidding on that one.)

Anyway, I probably won’t be using it myself, at least not until the promised Linux port happens (and, even then, I think Straw has it beat in the features department, although Jäger does have some neat built-in heuristics for dealing with blogs that don’t have syndication feeds), but if you live in Windows it’s probably worth taking for a spin.

Friday, 26 March 2004

Huzzah and kudos

Congratulations to Roberto Antonio Ferreira De Almeida on finishing his port of Textile 2 syntax to Python. I’ll be shunting it in “behind the scenes” here at Signifying Nothing shortly.

Wednesday, 25 February 2004

Another PyTextile 2 port

I see someone else is trying to make a Python port of the Textile 2 syntax. My approach so far has been a straight port of the Perl code by Brad Choate, with some minor tweaks (using urlparse and mimetypes, for example), rather than trying to hack Mark’s existing module.

Now that I’ve been hacking away for a week (and am about 700 lines away from being done—I just started on format_table, which looks downright nasty), I’m becoming convinced that the smarter plan would have been to write a lexer from scratch for the Textile markup, rather than trying to use the regex-happy approach Choate used (which works far, far better in Perl than in Python).

Friday, 13 February 2004

Project

This weekend’s Herculean coding task: port Textile 2.0 syntax to Python. Mark Pilgrim ported the 1.0 syntax, but has since put the project aside due to limited time. The Perl module is 2260 lines, not including the POD-formatted docs (I guess I’ll have to make that a docstring), so my work is cut out for me.

Anyway, it’s a welcome distraction from job applications…

Thursday, 4 September 2003

Porting to GNOME2

I’ve been pulling my hair out porting my positively ancient RoutePlanner program from GNOME 1 to GNOME 2 and trying to do it the “right” way—eschewing the old, working (but deprecated), humanly-comprehensible GtkCList widget for GtkTreeView [sic] and its friends. Actually, I would have stuck with GtkCList, but apparently the automated Glade conversion script decided to convert all of my widgets to use GtkTreeView. Damn annoying.

No doubt all this abstraction (separating the list into column view, overall view, iterator, storage, and selection objects) is a wonderful idea on paper, but in practice it’s a recipe for a giant headache, especially when trying to translate between the mostly-complete C API documentation and the virtually-undocumented Python API.

Saturday, 23 November 2002

More Python goodness for 2.2 and 2.3 (updated)

Want to iterate over a file? Try this on for size:

for line in open('/etc/passwd'):  # You could also use file('/etc/passwd')
    logname, x, uid = line.split(':')[:2]
    print 'user %s has uid %s' % (logname, uid)

You'd probably want to use the pwd module instead if you need to access the passwd database portably; this was meant as a simple example. :-)

Explanation: In Python 2.2 and later, file objects have a built-in iterator, which allows the lines in a file to be iterated over in a "for" loop. This is more memory efficient than the lines=f.readlines() semantic and easier to read than using the relatively new xreadlines() method.

You can also iterate over dictionaries now, as well as any class that defines a __next__ method. This is particularly useful when combined with generators, which are basically functions that preserve state between calls. xrange() and xreadlines() are now implemented this way. Of course, sequences (lists, tuples, strings) have their own built-in iterators too for backwards-compatibility :-)

Python 2.2 also has additional cool dictionary features; you can use "in" and "not in" instead of using dict.has_key(). "in" can also be implemented in classes using the __contains__ method. (Also, 2.3 extends "in" to allow multicharacter strings, so you can use the much cleaner if 'hell' in 'hello' instead of if 'hello'.find('hell') != -1.)

Another productivity tip for 2.2 and later: use help(object) at the interpreter prompt to get documentation for that object; it works best with modules and classes.

Friday, 22 November 2002

Python 2.3 goodness

A few interesting things in the next stable release, to whet your appetite:

for (i, x) in enumerate(['Zero', 'One', 'Two']):
   print i, x
from sets import Set
set1 = Set([2,4,6,8,10,12])
set2 = Set([3,6,9,12])
print set1 & set2 # S1 intersection S2
print set1 | set2 # S1 union S2
print set1 ^ set2 # Symmetric difference of S1 and S2

Also, some links for those of you interested in nested scopes (added as a 2.1 extension), long integer/integer unification (added in 2.2), and some new 2.3 features: the logging module (basically, a Pythonic syslog) and the integrated advanced option parser (formerly known as Optik).