Python在不进入交互模式的情况下获取文档字符串 [英] Python Get Docstring Without Going into Interactive Mode
本文介绍了Python在不进入交互模式的情况下获取文档字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在命令行应用程序中获取文档字符串,但是每次调用内置的help()函数时,Python都会进入交互模式.
I want to grab the docstring in my commandline application, but every time I call the builtin help() function, Python goes into interactive mode.
如何获取对象的文档字符串,并且不没有获得Python焦点?
How do I get the docstring of an object and not have Python grab focus?
推荐答案
任何文档字符串都可以通过.__doc__
属性获得:
Any docstring is available through the .__doc__
property:
>>> print str.__doc__
在python 3中,您需要使用括号进行打印:
In python 3, you'll need parenthesis for printing:
>>> print(str.__doc__)
这篇关于Python在不进入交互模式的情况下获取文档字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文