Automatically set the __package__ attribute of a script.
Project description
set-package-attribute
Run modules inside packages as scripts. Automatically sets the __package__
attribute of any script which imports it and calls the initialization function
set_package_attribute.init()
. This is usually done so that the usual
intra-package imports work for scripts inside packages.
For full documentation, see https://abarker.github.io/set-package-attribute.
Also available on PyPI for installation with pip.
Brief usage summary
To use the package just import it before any of the non-system files, inside any
module that you might want to run as a script, and call the init
function.
These statements should be inside a guard conditional, so that they only run
when the module is executed as a script:
if __name__ == "__main__": import set_package_attribute set_package_attribute.init()
Nothing else is required. The init
function must be called before any
within-package explicit relative imports, and before importing any modules from
within the same package which themselves use such imports.
If you are happy with the default init
arguments then there is a shortcut
import which automatically calls init
for you:
if __name__ == "__main__": import set_package_attribute_magic
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Hashes for set-package-attribute-0.2.3.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | a382244d1ba33f44879386b8c6f9c08c4730df234d462c9f15e3a5d8b4b2145c |
|
MD5 | 13f648641a7ddf46b8746825a0b424b9 |
|
BLAKE2b-256 | 57a9a9079c5b4b0382725413c1639d7d96b6989f45616d1f8cd176a81572f279 |