path module

Jason Orendorff jason.orendorff at lumigent.com
Fri Jul 25 16:19:49 EDT 2003


holger krekel wrote:
> IMO you'll almost never use the following string-methods on a 'Path' object:
>     capitalize center count decode encode [...]
> and so these methods pollute a Path object's name-space quite a bit. 
> Also 'join', '__contains__', startswith etc. produce some ambigouity.

I'm not worried about "namespace pollution", but you're right that
strings and paths are generally used for different things.  I also
agree 'join()' is a wart.

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

Hmmm.  If the plan were to convert the whole standard library to accept
path objects for pathnames, I would likely agree.  But when you say
"str(p)" is "convenient enough", you're saying I need this rule in my head:

    Don't pass path objects to functions that take path arguments.
    Pass string objects instead.

This is a type rule.  Such a thing has no place in Python.

Furthermore, this rule is counterlogical!  I would have to change
"mimetypes.guess_type(mypath)" to "mimetypes.guess_type(str(mypath))".

-- j




More information about the Python-list mailing list