Skip to content

Commit af50c84

Browse files
authored
bpo-43644: Add docs for importlib.resources.as_file. (#25048)
1 parent 29c451c commit af50c84

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
@@ -891,6 +891,22 @@ The following functions are available.
891891

892892
.. versionadded:: 3.9
893893

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

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

0 commit comments

Comments
 (0)