Created
October 12, 2021 17:37
-
-
Save rochacbruno/adb80404c5749e5c726910480a238a97 to your computer and use it in GitHub Desktop.
better main for python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import atexit | |
import sys | |
def main(f): | |
if f.__module__ == "__main__": | |
atexit.register(f) | |
sys.modules['main'] = main # noqa |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import main | |
@main | |
def my_main_function(): | |
print("This is my main function") | |
print("this runs first") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment