summaryrefslogtreecommitdiffstats
path: root/Doc/library/pathlib.rst
diff options
context:
space:
mode:
authorGuido van Rossum <guido@dropbox.com>2016-01-06 19:37:52 (GMT)
committerGuido van Rossum <guido@dropbox.com>2016-01-06 19:37:52 (GMT)
commitf08a308ebb9cbec07f2f15123c2238ab34ea65b8 (patch)
tree277452e15f4ee0be0b8a514ee27a41f5ec874dbf /Doc/library/pathlib.rst
parent483397a235630385c893941fee76379041612ee5 (diff)
parent1469d744bccbf7c6357bd23f06851d70f538f7e6 (diff)
downloadcpython-f08a308ebb9cbec07f2f15123c2238ab34ea65b8.zip
cpython-f08a308ebb9cbec07f2f15123c2238ab34ea65b8.tar.gz
cpython-f08a308ebb9cbec07f2f15123c2238ab34ea65b8.tar.bz2
Docs for issue #22570. (Merge 3.5->3.6)
Diffstat (limited to 'Doc/library/pathlib.rst')
-rw-r--r--Doc/library/pathlib.rst22
1 files changed, 22 insertions, 0 deletions
diff --git a/Doc/library/pathlib.rst b/Doc/library/pathlib.rst
index ff5196d..5ff8be8 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::