Replace subscription with slashing

This commit is contained in:
Antoine Pitrou 2012-11-07 20:25:27 +01:00
parent 7b8178a28b
commit ee6f30d19a
1 changed files with 7 additions and 5 deletions

View File

@ -360,20 +360,22 @@ Deriving new paths
Joining
^^^^^^^
A path can be joined with another using the ``__getitem__`` operator::
A path can be joined with another using the ``/`` operator::
>>> p = PurePosixPath('foo')
>>> p['bar']
>>> p / 'bar'
PurePosixPath('foo/bar')
>>> p[PurePosixPath('bar')]
>>> p / PurePosixPath('bar')
PurePosixPath('foo/bar')
>>> 'bar' / p
PurePosixPath('bar/foo')
As with the constructor, multiple path components can be specified, either
collapsed or separately::
>>> p['bar/xyzzy']
>>> p / 'bar/xyzzy'
PurePosixPath('foo/bar/xyzzy')
>>> p['bar', 'xyzzy']
>>> p / 'bar' / 'xyzzy'
PurePosixPath('foo/bar/xyzzy')
A joinpath() method is also provided, with the same behaviour. It can serve