The end to __name__ == __main__
Project description
The end to if __name__ == "__main__":!
Are you tired of writing if __name__ == "__main__": main() at the end of every script?
Ever wished for a cleaner, better, simpler wait to call main()?
Do you enjoy abusing the import system?
Well, today’s your lucky day!
Just import unmain and we’ll do the dirty work for you!
import unmain
def main():
print("Hello, unmain!")
Wow!
Installation & Usage
Installing and using unmain is easy!
- Install
pip install unmain
- Import
import unmain
That’s it! Unmain will find your main() function and call it for you.
Practical Considerations
Unmain abuses the import system to re-import your main module, then running main() from it. To avoid running global code twice - pleace import unmain at the top of your script file. Any code above the import location will be executed twice.
Additionally, the entire module will execute before main() is run. You can place your main() function anywhere in your script file.
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 Distributions
Built Distribution
File details
Details for the file unmain-1.0.0-py2.py3-none-any.whl
.
File metadata
- Download URL: unmain-1.0.0-py2.py3-none-any.whl
- Upload date:
- Size: 2.9 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.40.0 CPython/3.7.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | fab2efcba0a5522491f0ce7bdc89bab26af83795b39611b84c7b432f197b00c0 |
|
MD5 | e08041cfc868ab6ee5576c4f705f46d1 |
|
BLAKE2b-256 | 4f34976629ba60631bd6445c203dd20af64199844576d380959731581e3f7be7 |