[Python-checkins] bpo-43644: Add docs for importlib.resources.as_file. (#25048)

jaraco webhook-mailer at python.org
Sat Mar 27 20:26:00 EDT 2021

commit: af50c84643ce21cfbdfdabbdfae6bd5e1368c542
branch: master
author: Jason R. Coombs <jaraco at jaraco.com>
committer: jaraco <jaraco at jaraco.com>
date: 2021-03-27T20:25:53-04:00

bpo-43644: Add docs for importlib.resources.as_file. (#25048)

M Doc/library/importlib.rst

diff --git a/Doc/library/importlib.rst b/Doc/library/importlib.rst
index d9b790e4e777d..6515cdbc8d329 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*.

More information about the Python-checkins mailing list