I want to grab the docstring in my commandline application, but every time I call the builtin help() function, Python goes into interactive mode.
How do I get the docstring of an object and not have Python grab focus?
I want to grab the docstring in my commandline application, but every time I call the builtin help() function, Python goes into interactive mode.
How do I get the docstring of an object and not have Python grab focus?
.__doc__
次のプロパティを介して任意の docstring を使用できます。
>>> print str.__doc__
Python 3 では、印刷に括弧が必要になります。
>>> print(str.__doc__)
dir(
{insert class name here}を使用)
して、クラスの内容を取得し、それを繰り返し処理して、メソッドやその他のものを探すことができます。Task
この例では、名前で始まるメソッドをクラスで検索し、cmd
そのドキュメント文字列を取得します。
command_help = dict()
for key in dir( Task ):
if key.startswith( 'cmd' ):
command_help[ key ] = getattr( Task, key ).__doc__