Being fairly new to python I only recently discovered the ability to directly execute a .zip file by placing a __main__.py
file at the top of the file. This works great for python code, but can I bundle other types of files and access them with my scripts? If so, how?
My ultimate goal would be to bundle some image files along with the python code in a single .zip file, then be able to use those images within the app without having to extract them to disk. I also would like to bundle a copyright notice, release notes, etc so that the entire app and its data files is in a single zip that can be executed without having to extract it somewhere.
You could use
pkg_resources
functions to access files:Where zipfile contains:
To make zipfile executable, run:
To test it: