Skip to content

Commit 81741c5

Browse files
author
Matthias Koeppe
committed
src/doc/en/developer/coding_basics.rst: Remove advice on how to import from importlib.resources, fix markup
1 parent 0c28f6f commit 81741c5

File tree

1 file changed

+8
-19
lines changed

1 file changed

+8
-19
lines changed

src/doc/en/developer/coding_basics.rst

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -159,25 +159,14 @@ included in one of the following places:
159159
The preferred way to access the data from Python is using the
160160
`importlib.resources API <https://importlib-resources.readthedocs.io/en/latest/using.html>`,
161161
in particular the function :func:`importlib.resources.files`.
162-
It should be imported as follows
163-
(see :ref:`section-python-language-standard`)::
164-
165-
import sys
166-
167-
if sys.version_info < (3, 11):
168-
# Use backport package providing Python 3.11 features
169-
from importlib_resources import files
170-
else:
171-
from importlib.resources import files
172-
173-
After this import, you can:
174-
175-
- open a resource for text reading: `fd = files(package).joinpath(resource).open('rt')`
176-
- open a resource for binary reading: `fd = files(package).joinpath(resource).open('rb')`
177-
- read a resource as text: `text = files(package).joinpath(resource).read_text()`
178-
- read a resource as bytes: `bytes = files(package).joinpath(resource).read_bytes()`
179-
- open a xz resource for text reading: `fd = lzma.open(files(package).joinpath(resource).open('rb'), 'rt')`
180-
- open a xz resource for binary reading: `fd = lzma.open(files(package).joinpath(resource).open('rb'), 'rb')`
162+
Using it, you can:
163+
164+
- open a resource for text reading: ``fd = files(package).joinpath(resource).open('rt')``
165+
- open a resource for binary reading: ``fd = files(package).joinpath(resource).open('rb')``
166+
- read a resource as text: ``text = files(package).joinpath(resource).read_text()``
167+
- read a resource as bytes: ``bytes = files(package).joinpath(resource).read_bytes()``
168+
- open an xz-compressed resource for text reading: ``fd = lzma.open(files(package).joinpath(resource).open('rb'), 'rt')``
169+
- open an xz-compressed resource for binary reading: ``fd = lzma.open(files(package).joinpath(resource).open('rb'), 'rb')``
181170

182171
If the file needs to be used outside of Python, then the
183172
preferred way is using the context manager

0 commit comments

Comments
 (0)