Skip to content

Instantly share code, notes, and snippets.

@FFY00
Created November 17, 2022 18:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save FFY00/d3c969764b72e8c5214202afd190a52e to your computer and use it in GitHub Desktop.
Save FFY00/d3c969764b72e8c5214202afd190a52e to your computer and use it in GitHub Desktop.
Load package resources contents
$ 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