الفرق بين المراجعتين ل"Python/pathlib/Path/resolve"

من موسوعة حسوب
< Python‏ | pathlib‏ | Path
اذهب إلى التنقل اذهب إلى البحث
سطر 1: سطر 1:
 
== التابع Path.resolve ==
 
== التابع Path.resolve ==
Make the path absolute, resolving any symlinks. A new path object is returned:<syntaxhighlight lang="python3">
+
يجعل المسار مسارًا مطلقًا، حيث يقوم بإزالة جميع الاختصارات (symlinks)، ويقوم بإعادة كائن مسار جديد.<syntaxhighlight lang="python3">
 
>>> p = Path()
 
>>> p = Path()
  

مراجعة 08:11، 3 أغسطس 2018

التابع Path.resolve

يجعل المسار مسارًا مطلقًا، حيث يقوم بإزالة جميع الاختصارات (symlinks)، ويقوم بإعادة كائن مسار جديد.

>>> 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.