Argument analysis should always be done with argparse .
You can display the string __doc__ by passing it to the description parameter of Argparse:
#!/usr/bin/env python """ This describes the script. """ if __name__ == '__main__': from argparse import ArgumentParser parser = ArgumentParser(description=__doc__) # Add your arguments here parser.add_argument("-f", "--file", dest="myFilenameVariable", required=True, help="write report to FILE", metavar="FILE") args = parser.parse_args() print(args.myFilenameVariable)
If you call this mysuperscript.py and execute it, you get:
$ ./mysuperscript.py --help usage: mysuperscript.py [-h] -f FILE This describes the script. optional arguments: -h, --help show this help message and exit -f FILE, --file FILE write report to FILE
Martin Thoma Jul 28 '14 at 16:51 2014-07-28 16:51
source share