path module

Jason Orendorff jason.orendorff at lumigent.com
Mon Jul 21 14:16:57 EDT 2003


I wrote the 'path' module at:
    http://www.jorendorff.com/articles/python/path

There was some discussion on it here:
    http://groups.google.com/groups?th=42ab4db337b60ce3

Just a few comments:

Ian and Holger wondered why 'path' should subclass 'str'.  It's because
a path is a string.  Benefit: you can pass 'path' objects to functions
that expect strings (like functions in 'win32file').  I find this
really useful in practice.

I agree with Just that 'path' shouldn't override '__iter__()'.  I'll
change this eventually.

I think Just is the first to argue that 'path / filename' is confusing.
I find it intuitive.  Other people have chosen / for this purpose,
independently:  see the O'Reilly book _Python Cookbook_ [1], recipe 4.17,
and the Boost path object [2].

I do believe 'path' should be in the standard library (if not builtin).
I enjoy it and I use it all the time.  My perception is that the Python
core dev team doesn't see any particular need for it.  If anyone wants me
to, I'll write the PEP.

    for f in path('/music').walkfiles('*.mp3'):
        play_mp3(f)

Cheers,
Jason

[1] http://safari.oreilly.com/?xmlid=0-596-00167-3
[2] http://www.boost.org/libs/filesystem/doc/path.htm#operator_slash




More information about the Python-list mailing list