summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJason R. Coombs <jaraco@jaraco.com>2021-03-28 00:25:53 (GMT)
committerGitHub <noreply@github.com>2021-03-28 00:25:53 (GMT)
commitaf50c84643ce21cfbdfdabbdfae6bd5e1368c542 (patch)
treed194ead8b087f242347dba8aef5106b6b8d9f3ec
parent29c451c6989c3c94fa0a9facf187c24f3cbf2420 (diff)
downloadcpython-af50c84643ce21cfbdfdabbdfae6bd5e1368c542.zip
cpython-af50c84643ce21cfbdfdabbdfae6bd5e1368c542.tar.gz
cpython-af50c84643ce21cfbdfdabbdfae6bd5e1368c542.tar.bz2
bpo-43644: Add docs for importlib.resources.as_file. (#25048)
-rw-r--r--Doc/library/importlib.rst16
1 files changed, 16 insertions, 0 deletions
diff --git a/Doc/library/importlib.rst b/Doc/library/importlib.rst
index d9b790e..6515cdb 100644
--- a/Doc/library/importlib.rst
+++ b/Doc/library/importlib.rst
@@ -891,6 +891,22 @@ The following functions are available.
.. versionadded:: 3.9
+.. function:: as_file(traversable)
+
+ Given a :class:`importlib.resources.abc.Traversable` object representing
+ a file, typically from :func:`importlib.resources.files`, return
+ a context manager for use in a :keyword:`with` statement.
+ The context manager provides a :class:`pathlib.Path` object.
+
+ Exiting the context manager cleans up any temporary file created when the
+ resource was extracted from e.g. a zip file.
+
+ Use ``as_file`` when the Traversable methods
+ (``read_text``, etc) are insufficient and an actual file on
+ the file system is required.
+
+ .. versionadded:: 3.9
+
.. function:: open_binary(package, resource)
Open for binary reading the *resource* within *package*.