How can I print a Python file's docstring when executing it?

后端 未结 4 998
南笙
南笙 2020-12-29 01:49

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.

4条回答
  •  盖世英雄少女心
    2020-12-29 02:41

    The docstring is stored in the module's __doc__ global.

    print(__doc__)
    

    By the way, this goes for any module: import sys; print(sys.__doc__). Docstrings of functions and classes are also in their __doc__ attribute.

提交回复
热议问题