pathlib.Path.resolve()

Path.resolve()

Make the path absolute, resolving any symlinks. A new path object is returned:

>>> p = Path()
>>> p
PosixPath('.')
>>> p.resolve()
PosixPath('/home/antoine/pathlib')

”..” components are also eliminated (this is the only method to do so):

>>> p = Path('docs/../setup.py')
>>> p.resolve()
PosixPath('/home/antoine/pathlib/setup.py')

If the path doesn’t exist, FileNotFoundError is raised. If an infinite loop is encountered along the resolution path, RuntimeError is raised.

doc_python
2016-10-07 17:40:31
Comments
Leave a Comment

Please login to continue.