python “help” function: printing docstrings

前端 未结 4 1796
小鲜肉
小鲜肉 2020-12-09 17:30

Is there an option to print the output of help(\'myfun\'). The behaviour I\'m seeing is that output is printed to std.out and the script waits for user input (i.e. type \'q\

4条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-09 18:16

    To get exactly the help that's printed by help(str) into the variable strhelp:

    import pydoc
    strhelp = pydoc.render_doc(str, "Help on %s")
    

    Of course you can then easily print it without paging, etc.

提交回复
热议问题