[path-PEP] Path inherits from basestring again

Peter Hansen peter at engcorp.com
Fri Jul 29 13:54:18 CEST 2005


Tony Meyer wrote:
> Would you really choose this:
>     p = Path() / "build" / "a" / "very" / "very" / "long" / "path"
> 
> Over this:
>     p = Path(os.path.join("build", "a", "very", "very", "long", "path"))

I'd choose neither, because both are contrived examples (who builds 
paths out of six literals like that?) and the second one is not 
something anyone would want, since it mixes Paths and old-style 
os.path.join() calls.

We're talking at this point about how Path should work, not whether it's 
preferable to os.path.join, even though that was really the point of 
Reinhard's original post.  Given that, then, of the following two I 
would prefer the first one, slightly:

   p = somePath / user.getFolder() / 'archive' / oldPath + '.bak'

   p = somePath.joinpath(user.getFolder(), 'archive', oldPath + '.bak')

> ?  A saving of six characters, and the second one is a lot clearer.  

It's not a question of saving characters, but readability which, as 
you've said, is a matter of opinion.

I find the former more readable.  Somewhat.  Not enough to make a big 
deal about it.

I can live with the latter, but as *someone who has used the path module 
already* I can only say that you might want to try it for a few months 
before condemning the approach using / as being unacceptable.

-Peter



More information about the Python-list mailing list