The "path" module

Somewhat belatedly I’ve started using Jason Orendorff’s path module for Python. It’s great. Here’s a comparison with the stock os.path facilities, grabbed from Jason’s site:

# with os.path.walk
def delete_backups(arg, dirname, names):
    for name in names:
        if name.endswith('~'):
            os.remove(os.path.join(dirname, name))
os.path.walk(os.environ['HOME'], delete_backups, None)

# with path
d = path(os.environ['HOME'])
for f in d.walkfiles('*~'):
    f.remove()

The second snippet is not just shorter, it’s easier to read and easier to write. I’m writing some code to recursively process a tree of short text files (Blosxom entries), and the path module is a godsend. If you’re curious, see the description and examples on Jason’s site; he also posted some interesting comments on Ian Bicking’s blog about the design of the module.

I gather that there was significant interest in getting some version of this module included in Python 2.5, but I don’t see any mention of it in the release notes. There’s PEP 355 and a python-dev discussion from January. But unless I missed something (I’m still mostly using Python 2.4), it’s not in 2.5 in any form. Here’s hoping it makes it into 2.6…

Update: Bummer. Dead.

Lawrence Oluyede commented on Fri Sep 29 13:36:08 2006:

Seems someone heard you: http://mail.python.org/pipermail/python-dev/2006-September/069059.html


Paul commented on Fri Sep 29 13:37:55 2006:

Good find – thanks, Lawrence!


Lawrence Oluyede commented on Fri Sep 29 17:55:57 2006:

GvR just said the path module will not get into Python so… that’s it.


Paul commented on Fri Sep 29 18:28:11 2006:

Yeah, I saw that and added my “bummer” update link above. Oh well. I guess it will just be part of my own little library for now.



Share: