Automatically set the __package__ attribute of a script.
Project description
set-package-attribute
Automatically sets the __package__
attribute of any script which imports it
and calls set_package_attribute.init()
. This is usually done so that
explicit intra-package relative 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 its 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.
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.1.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 07ab9cd09f5fe4809838a563e9c27fc9946fe3286decd7d1be37ffd56c693580 |
|
MD5 | 7a1763931179644737a20aaeaa3cfd5d |
|
BLAKE2b-256 | 9300900a027d14d67fce76ee03b4a6aa62257905130d7f6f93d11f1579f07595 |