Skip to content

rec/def_main

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

def_main: a tiny decorator to define main

Define the main function in one step.

For any non-trivial projects, use typer and dtyper instead!

Usage example

Without an return code

import def_main

@def_main
def main(*argv):
    print('hello,', *argv)

means precisely the same as:

def main(*argv):
    print('hello,', *argv)


if __name__ == '__main__':
    import sys

    main(sys.argv[1:])

With a return code

import def_main

@def_main
def main(*argv):
    print('hello,', *argv)
    return argv

means precisely the same as:

def main(*argv):
    print('hello,', *argv)
    return argv


if __name__ == '__main__':
    import sys

    returncode = main(sys.argv[1:])
    sys.exit(returncode)

About

🗣 A decorator for main 🗣

Resources

Stars

Watchers

Forks

Sponsor this project

 

Packages

No packages published

Languages