]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-43644: Add docs for importlib.resources.as_file. (#25048)
authorJason R. Coombs <jaraco@jaraco.com>
Sun, 28 Mar 2021 00:25:53 +0000 (20:25 -0400)
committerGitHub <noreply@github.com>
Sun, 28 Mar 2021 00:25:53 +0000 (20:25 -0400)
Doc/library/importlib.rst

index d9b790e4e777de3f2a86f0f4351d1cb40fa3f31e..6515cdbc8d32978bfc8868cdc207de34821f726c 100644 (file)
@@ -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*.