Skip to main content

C-Like main method support

Project description

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.

Project details


Download files

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

Source Distribution

mainmethod-0.1.1.tar.gz (2.2 kB view details)

Uploaded Source

File details

Details for the file mainmethod-0.1.1.tar.gz.

File metadata

  • Download URL: mainmethod-0.1.1.tar.gz
  • Upload date:
  • Size: 2.2 kB
  • Tags: Source
  • Uploaded using 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

File hashes

Hashes for mainmethod-0.1.1.tar.gz
Algorithm Hash digest
SHA256 c666a1e89997ecd2c89cf63bf5db58ae71cb0298c324673922ed4fe214ac0e64
MD5 63aebf8549ad624e2353ca7027ba98b1
BLAKE2b-256 52b9d03ab3518fee2d60e0aaef3ef37aaea8bff318da2dc55ca51c86d5c19bf4

See more details on using hashes here.

Supported by

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