[Python-ideas] PEP 428 - object-oriented filesystem paths
Ethan Furman
ethan at stoneleaf.us
Fri Oct 5 21:44:07 CEST 2012
Paul Moore wrote:
> On 5 October 2012 19:25, Antoine Pitrou <solipsis at pitrou.net> wrote:
>> A path can be joined with another using the ``__getitem__`` operator::
>>
>> >>> p = PurePosixPath('foo')
>> >>> p['bar']
>> PurePosixPath('foo/bar')
>> >>> p[PurePosixPath('bar')]
>> PurePosixPath('foo/bar')
>
> There is a risk that this is too "cute". However, it's probably better
> than overloading the '/' operator, and you do need something short.
I actually like using the '/' operator for this. My own path module
uses it, and the resulting code is along the lines of:
job = Path('c:/orders/38273')
table = dbf.Table(job/'ABC12345')
>> As with constructing, multiple path components can be specified at once::
>>
>> >>> p['bar/xyzzy']
>> PurePosixPath('foo/bar/xyzzy')
>
> That's risky. Are you proposing always using '/' regardless of OS?
Mine does; it also accepts `\\` on Windows machines. Personally, I
don't care for the index notation Antoine is suggesting.
~Ethan~
More information about the Python-ideas
mailing list