الفرق بين المراجعتين لصفحة: «Python/pathlib/Path/resolve»

من موسوعة حسوب
< Python‏ | pathlib‏ | Path
أنشأ الصفحة ب'== التابع Path.cwd == يعيد كائن مسار جديدًا يمثّل المسار الحالي (بشكل مشابه للتابع os.getcwd)<syntaxhighlight lan...'
 
سطر 1: سطر 1:
== التابع Path.cwd ==
== التابع Path.resolve ==
يعيد كائن مسار جديدًا يمثّل المسار الحالي (بشكل مشابه للتابع os.getcwd)<syntaxhighlight lang="python3">
Make the path absolute, resolving any symlinks. A new path object is returned:<syntaxhighlight lang="python3">
>>> Path.cwd()
>>> p = Path()


>>> p
PosixPath('.')
>>> p.resolve()
PosixPath('/home/antoine/pathlib')
PosixPath('/home/antoine/pathlib')
</syntaxhighlight>“..” components are also eliminated (this is the only method to do so):<syntaxhighlight lang="python3">
>>> p = Path('docs/../setup.py')
>>> p.resolve()
PosixPath('/home/antoine/pathlib/setup.py')
</syntaxhighlight>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.


<span> </span>


</syntaxhighlight><span> </span>
New in version 3.6: The strict argument.

مراجعة 07:30، 3 أغسطس 2018

التابع 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.