Created
November 17, 2022 18:42
-
-
Save FFY00/d3c969764b72e8c5214202afd190a52e to your computer and use it in GitHub Desktop.
Load package resources contents
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ tree | |
. | |
└── package | |
├── a | |
├── b | |
└── c | |
1 directory, 3 files | |
$ python | |
Python 3.10.8 (main, Nov 1 2022, 14:18:21) [GCC 12.2.0] on linux | |
Type "help", "copyright", "credits" or "license" for more information. | |
>>> import importlib.resources as r | |
>>> t = r.files('package') | |
>>> contents = {t2.name: t2.read_text() for t2 in t.iterdir() if t2.is_file()} | |
>>> contents | |
{'a': 'aaa\n', 'c': 'ccc\n', 'b': 'bbb\n'} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment