Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
171 views
in Technique[技术] by (71.8m points)

python "help" function: printing docstrings

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' to continue).

There must be a setting to set this to just dump docstrings.

Alternatively, if I could just dump the docstring PLUS the "def f(args):" line that would be fine too.

Searching for "python help function" is comical. :) Maybe I'm missing some nice pydoc page somewhere out there that explains it all?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...