[Python-ideas] PEP 428 - object-oriented filesystem paths

Oleg Broytman phd at phdru.name
Fri Oct 5 21:16:25 CEST 2012


On Fri, Oct 05, 2012 at 08:25:34PM +0200, Antoine Pitrou <solipsis at pitrou.net> wrote:
> This PEP proposes the inclusion of a third-party module, `pathlib`_, in
> the standard library.

   +1 from me for a sane path handling in the stdlib!

>     >>> p = Path('/home/antoine/pathlib/setup.py')
>     >>> p.name
>     'setup.py'
>     >>> p.ext
>     '.py'
>     >>> p.root
>     '/'
>     >>> p.parts
>     <PosixPath.parts: ['/', 'home', 'antoine', 'pathlib', 'setup.py']>
>     >>> list(p.parents())
>     [PosixPath('/home/antoine/pathlib'), PosixPath('/home/antoine'), PosixPath('/home'), PosixPath('/')]

   Some attributes are properties and some are methods. Which is which?
Why .root is a property but .parents() is a method? .owner/.group are
properties but .exists() is a method, and so on. .stat() just returns
self._stat, but said ._stat is a property!

>   A Windows UNC path (e.g.
>   ``\\some\\share\\myfile.txt``) always has a drive and a root
>   (here, ``\\some\\share`` and ``\\``, respectively).

   If I understand it correctly these should are either
\\\\some\\share\\myfile.txt and \\\\some\\share
\\some\share\myfile.txt and \\some\share

     Oleg Broytman            http://phdru.name/            phd at phdru.name
           Programmers don't die, they just GOSUB without RETURN.

More information about the Python-ideas mailing list