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

Ethan Furman ethan at stoneleaf.us
Sat Oct 6 00:21:06 CEST 2012


Oleg Broytman wrote:
> 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.

They are on Windows (no comment on whether or not it qualifies as an OS ;).

c:\temp>dir \\\\\temp
The filename, directory name, or volume label syntax is incorrect.

c:\temp>dir \\temp
The filename, directory name, or volume label syntax is incorrect.

Although I see it works fine in between path pieces:

c:\temp\34400>dir \temp\\\34400
[snip listing]


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

Cool, thanks.

~Ethan~



More information about the Python-ideas mailing list