path module

holger krekel pyth at devel.trillke.net
Fri Jul 25 16:37:57 CEST 2003


Jason Orendorff wrote:
> 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.

IMO you'll almost never use the following string-methods on a 'Path' object:

    capitalize center count decode encode
    expandtabs find index isalnum isalpha isdigit
    islower isspace istitle isupper 
    ljust lstrip rjust splitlines startswith
    swapcase title translate zfill

and so these methods pollute a Path object's name-space quite a bit. 
Also 'join', '__contains__', startswith etc. produce some ambigouity.

I think it's convenient enough to use "str(path)" if passing a 'path' 
instance as a string somewhere.

cheers,

    holger





More information about the Python-list mailing list