python - Display pydoc's description as part of argparse '--help' -


i using argparse.argumentparser() in script, display pydoc description of script part of '--help' option of argparse.

one possibly solution can use formatter_class or description attribute of argumentparser configure displaying of help. in case, need use 'pydoc' command internally fetch description.

do have other ways (possibly elegant) it?

you can retrieve docstring of script __doc__ global. add script's help, can set description argument of parser.

"""my python script  script process file """  p = argparse.argumentparser(description=__doc__,                             formatter_class=argparse.rawdescriptionhelpformatter) p.add_argument('foo', help="name of file process") p.parse_args() 

then like:

$ python tmp.py --help usage: tmp.py [-h] foo  python script  script process file  positional arguments:   foo         name of file process  optional arguments:   -h, --help  show message , exit 

you can use epilog keyword argument instead of description move docstring end of help, instead of following usage string.


Comments

Popular posts from this blog

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -

java - Why does my date parsing return a weird date? -

Need help in packaging app using TideSDK on Windows -