I have a Python script with a docstring. When the parsing of the command-line arguments does not succeed, I want to print the docstring for the user\'s information.
This will print the __doc__ string when --help is the only argument.
__doc__
--help
if __name__=='__main__': if len(sys.argv)==2 and sys.argv[1]=='--help': print(__doc__)
Works for both:
./yourscriptname.py --help
python3 yourscriptname.py --help