The "parts" property now simply returns a tuple (the slightly magic slicing behaviour is gone)

This commit is contained in:
Antoine Pitrou 2013-11-19 21:48:55 +01:00
parent ea0c8221a0
commit ee543c9e5c
1 changed files with 5 additions and 16 deletions

View File

@ -216,7 +216,7 @@ Some examples::
>>> p.root
'/'
>>> p.parts
<PosixPath.parts: ['/', 'home', 'antoine', 'pathlib', 'setup.py']>
('/', 'home', 'antoine', 'pathlib', 'setup.py')
>>> p.relative_to('/home/antoine')
PosixPath('pathlib/setup.py')
>>> p.exists()
@ -469,29 +469,18 @@ ValueError is raised if the method cannot return a meaningful value::
Sequence-like access
--------------------
The ``parts`` property provides read-only sequence access to a path object::
The ``parts`` property returns a tuple providing read-only sequence access
to a path's components::
>>> p = PurePosixPath('/etc/init.d')
>>> p.parts
<PurePosixPath.parts: ['/', 'etc', 'init.d']>
Simple indexing returns the invidual path component as a string, while
slicing returns a new path object constructed from the selected components::
>>> p.parts[-1]
'init.d'
>>> p.parts[:-1]
PurePosixPath('/etc')
('/', 'etc', 'init.d')
Windows paths handle the drive and the root as a single path component::
>>> p = PureWindowsPath('c:/setup.py')
>>> p.parts
<PureWindowsPath.parts: ['c:\\', 'setup.py']>
>>> p.root
'\\'
>>> p.parts[0]
'c:\\'
('c:\\', 'setup.py')
(separating them would be wrong, since ``C:`` is not the parent of ``C:\\``).