path module

holger krekel pyth at devel.trillke.net
Fri Jul 25 16:46:38 EDT 2003


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

Or even better, call the appropriate Path method :-)
 
> This is a type rule.  Such a thing has no place in Python.

Oh, the stdlib has lots of places where it expects certain types in
certain places.  Look for e.g. 'isinstance'. 

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

I'd just call this a little inconvenient.  And i wouldn't mind adding
a guess_type method (which would work even better for URL's or
subversion-urls). 

cheers,

    holger





More information about the Python-list mailing list