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

Mathias Panzenböck grosser.meister.morti at gmx.net
Sat Oct 6 00:47:28 CEST 2012


On 10/06/2012 12:21 AM, Ethan Furman wrote:
> 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]
>

\\ at the start of a path has a special meaning under windows:
http://en.wikipedia.org/wiki/UNC_path#Uniform_Naming_Convention

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