Python/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 and strict is True, FileNotFoundError is raised. If strict is False, the path is resolved as far as possible and any remainder is appended without checking whether it exists. If an infinite loop is encountered along the resolution path, RuntimeError is raised.

New in version 3.6: The strict argument.