I wished it was possible to include octet-stream or plain text from a Python script, based on relative-path, without any runtime instructions. Some languages have this feature, as I know: Rust (let some_text = include_str!("./data.txt");
, let some_ba = include_bytes!("./data.bin");
), ActionScript ([Embed]
) and .NET languages (.NET languages combine project configuration and resource API for that).
Python’s compiler bytecode gives a good chance for the language to have this feature. The bytecode format could easily contain octet stream.
What I want would be something like:
some_ba = embed './data.bin': bytearray
some_text = embed './data.txt': str
If the script is located at project/src/lib.py
, then some_ba
resolves to the content located at project/src/data.bin
.
(NOTE embed
can be a context keyword followed by a string literal.)