diff options
-rw-r--r-- | Doc/library/os.rst | 6 | ||||
-rw-r--r-- | Doc/library/pathlib.rst | 22 |
2 files changed, 28 insertions, 0 deletions
diff --git a/Doc/library/os.rst b/Doc/library/os.rst index 373cafc525..9cb7e96be1 100644 --- a/Doc/library/os.rst +++ b/Doc/library/os.rst @@ -2035,6 +2035,12 @@ features: The result is cached on the ``DirEntry`` object. Call :func:`os.stat` to fetch up-to-date information. + Note that there is a nice correspondence between several attributes + and methods of ``DirEntry`` and of :class:`pathlib.Path`. In + particular, the ``name`` and ``path`` attributes have the same + meaning, as do the ``is_dir()``, ``is_file()``, ``is_symlink()`` + and ``stat()`` methods. + .. versionadded:: 3.5 diff --git a/Doc/library/pathlib.rst b/Doc/library/pathlib.rst index ff5196de86..5ff8be8980 100644 --- a/Doc/library/pathlib.rst +++ b/Doc/library/pathlib.rst @@ -365,6 +365,28 @@ Pure paths provide the following methods and properties: '' +.. data:: PurePath.path + + A string representing the full path:: + + >>> PurePosixPath('my/library/setup.py').path + 'my/library/setup.py' + + This always returns the same value as ``str(p)``; it is included to + serve as a one-off protocol. Code that wants to support both + strings and ``pathlib.Path`` objects as filenames can write + ``arg = getattr(arg, 'path', arg)`` to get the path as a string. + This can then be passed to various system calls or library + functions that expect a string. Unlike the alternative + ``arg = str(arg)``, this will still raise an exception if an object + of some other type is given by accident. + + A nice advantage is that this protocol is also supported by + :class:`os.DirEntry` objects returned by :func:`os.scandir`. + + .. versionadded:: 3.4.5 + .. versionadded:: 3.5.2 + .. data:: PurePath.suffix The file extension of the final component, if any:: |