Skip to main content

mainmethod.py

Provides C-like main method support.

Sample usage:

# file: script.py
from mainmethod import mainmethod

@mainmethod
def main():
    print('hello, world!')

Running the script defined above will execute the method main.

$ python script.py
hello, world

No more need for

if __name__ == '__main__':
    main()

The decorator inspects the method marked as main and supports these signatures;

  1. main(). -> No command line arguments.
  2. main(argv) (or main(args)) -> Get sys.argv passed to the main method call.
from mainmethod import mainmethod

@mainmethod
def main(argv):
    message = 'hello, world'

    if '--loud' in argv:
        message = message.upper()

    print(message)

The decorator also automatically gathers the return value from the main method and uses it as the return status code.

Release files for mainmethod 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mainmethod 0.1.1
File Size Uploaded
mainmethod-0.1.1.tar.gz 2.2 kB Details

Release files / mainmethod-0.1.1.tar.gz

Download URL mainmethod-0.1.1.tar.gz
Size 2.2 kB
Tags Source
SHA-256 checksum
How to use checksums
c666a1e89997ecd2c89cf63bf5db58ae71cb0298c324673922ed4fe214ac0e64
BLAKE2b-256 checksum
How to use checksums
52b9d03ab3518fee2d60e0aaef3ef37aaea8bff318da2dc55ca51c86d5c19bf4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/44.0.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.2

Release history Release notifications | RSS feed

This release

0.1.1 This release

1 release file

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page