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;
main()
. -> No command line arguments.main(argv)
(ormain(args)
) -> Getsys.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
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 Distribution
mainmethod-0.1.0.tar.gz
(2.2 kB
view hashes)
Built Distribution
Close
Hashes for mainmethod-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ab9040e8435ae8ff4d09b4189b7b744ac8db8854116304b7ad0add2e2783ec61 |
|
MD5 | 35a3802f831fec29f86c4031cceeeca7 |
|
BLAKE2b-256 | 8511bb03d682487722bc879a911ed5b065f621197982fd39535d381c0a7bde67 |