Skip to content

Commit 138e039

Browse files
bpo-43644: Add docs for importlib.resources.as_file. (GH-25048)
(cherry picked from commit af50c84) Co-authored-by: Jason R. Coombs <[email protected]>
1 parent 064bc07 commit 138e039

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

Doc/library/importlib.rst

+16
Original file line numberDiff line numberDiff line change
@@ -888,6 +888,22 @@ The following functions are available.
888888

889889
.. versionadded:: 3.9
890890

891+
.. function:: as_file(traversable)
892+
893+
Given a :class:`importlib.resources.abc.Traversable` object representing
894+
a file, typically from :func:`importlib.resources.files`, return
895+
a context manager for use in a :keyword:`with` statement.
896+
The context manager provides a :class:`pathlib.Path` object.
897+
898+
Exiting the context manager cleans up any temporary file created when the
899+
resource was extracted from e.g. a zip file.
900+
901+
Use ``as_file`` when the Traversable methods
902+
(``read_text``, etc) are insufficient and an actual file on
903+
the file system is required.
904+
905+
.. versionadded:: 3.9
906+
891907
.. function:: open_binary(package, resource)
892908

893909
Open for binary reading the *resource* within *package*.

0 commit comments

Comments
 (0)