Skip to main content

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!

  1. Install
    pip install unmain
  2. 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

unmain-1.0.0-py2.py3-none-any.whl (2.9 kB view hashes)

Uploaded Python 2 Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page