Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 28, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions Doc/library/importlib.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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*.
Expand Down