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

Oleg Broytman phd at phdru.name
Sat Oct 6 00:05:14 CEST 2012


On Fri, Oct 05, 2012 at 02:38:57PM -0700, Ethan Furman <ethan at stoneleaf.us> wrote:
> Antoine Pitrou wrote:
> >Extraneous path separators and ``"."`` components are eliminated::
> >
> >    >>> PurePath('a///b/c/./d/')
> >    PurePosixPath('a/b/c/d')
> 
> I'm all for eliminating extra '.'s, but shouldn't extra '/'s be an error?

   Why? They aren't errors in the underlying OS.

> >    >>> p = PureNTPath('c:/python33/bin/python.exe')
> >    >>> for parent in p.parents(): parent
> >    ...
> >    PureNTPath('c:\\python33\\bin')
> >    PureNTPath('c:\\python33')
> >    PureNTPath('c:\\')
> 
> What's the use-case for iterating through all the parent directories?

for parent in p.parents():
    if parent['.svn'].exists():
        last_seen = parent
        continue
    else:
        print("The topmost directory of the project: %s" % last_seen)
        break

Oleg.
-- 
     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