File tree Expand file tree Collapse file tree 6 files changed +33
-0
lines changed
Expand file tree Collapse file tree 6 files changed +33
-0
lines changed Original file line number Diff line number Diff line change @@ -35,3 +35,5 @@ was used to develop it.
35351 . ` error-handling ` : simple illustration of error handling.
36361 . ` pyinstaller ` : illustration of how to use ` pyinstaller ` to create
3737 standalone executables.
38+ 1 . ` text-resources ` : illustration on how to include text resources in
39+ a package and conveniently access them.
Original file line number Diff line number Diff line change 1+ # Text resources
2+
3+ It can be convenient to bundle text files in a package for convenient
4+ distribution and access.
5+
6+
7+ ## What is it?
8+
9+ 1 . ` show_text.py ` : script that reads a text file from the package, and
10+ prints it to standard output.
11+ 1 . `lib/utils': package with a text file.
12+ 1 . ` lib/utils/text_data.txt ` : text file that contains some text.
13+ 1 . ` run_show_text.sh ` : Bash script that runs the ` show_text.py ` script. It
14+ sets the ` PYTHONPATH ` environment variable to include the ` lib ` directory to
15+ find the ` utils ` package.
Original file line number Diff line number Diff line change 1+ This is a text
2+ with multiple lines
3+ to see how text resources
4+ work.
Original file line number Diff line number Diff line change 1+ #! /usr/bin/env bash
2+
3+ export PYTHONPATH=lib
4+
5+ python show_text.py
Original file line number Diff line number Diff line change 1+ #!/usr/bin/env python
2+
3+ import importlib .resources
4+
5+
6+ text = importlib .resources .read_text ('utils' , 'text_data.txt' )
7+ print (text )
You can’t perform that action at this time.
0 commit comments