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

Ethan Furman ethan at stoneleaf.us
Fri Oct 5 23:38:57 CEST 2012


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?


> The ``parent()`` method returns an ancestor of the path::
> 
>     >>> p.parent()
>     PureNTPath('c:\\python33\\bin')
>     >>> p.parent(2)
>     PureNTPath('c:\\python33')
>     >>> p.parent(3)
>     PureNTPath('c:\\')
> 
> The ``parents()`` method automates repeated invocations of ``parent()``, until
> the anchor is reached::
> 
>     >>> 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?



Say I have a .dbf table as PureNTPath('c:\orders\12345\abc67890.dbf'), 
and I export it to .csv in the same folder; how would I transform the 
above PureNTPath's ext from 'dbf' to 'csv'?

~Ethan~



More information about the Python-ideas mailing list