是否有打印帮助输出('myfun')的选项。我看到的行为是输出打印到std.out并且脚本等待用户输入(即键入'q'继续)。蟒蛇“帮助”功能:打印文档
必须有一个设置来设置它只是转储docstrings。
另外,如果我可以只是转储文件字符串PLUS“def f(args):”行,那也可以。
搜索“python帮助函数”是滑稽的。 :)也许我错过了一些不错的pydoc页面,它解释了这一切?
是否有打印帮助输出('myfun')的选项。我看到的行为是输出打印到std.out并且脚本等待用户输入(即键入'q'继续)。蟒蛇“帮助”功能:打印文档
必须有一个设置来设置它只是转储docstrings。
另外,如果我可以只是转储文件字符串PLUS“def f(args):”行,那也可以。
搜索“python帮助函数”是滑稽的。 :)也许我错过了一些不错的pydoc页面,它解释了这一切?
要得到完全多数民众赞成由help(str)
印入变量strhelp
帮助:
import pydoc
strhelp = pydoc.render_doc(str, "Help on %s")
当然你也可以那么轻松地打印无分页等
>>> x = 2
>>> x.__doc__
'int(x[, base]) -> integer\n\nConvert a string or number to an integer, if possi
ble. A floating point\nargument will be truncated towards zero (this does not i
nclude a string\nrepresentation of a floating point number!) When converting a
string, use\nthe optional base. It is an error to supply a base when converting
a\nnon-string. If the argument is outside the integer range a long object\nwill
be returned instead.'
这就是你需要的吗?
编辑 - 你可以print(x.__doc__)
和有关功能签名,你可以使用inspect
模块来建立它。
>>> inspect.formatargspec(inspect.getargspec(os.path.join))
'((a,), p, None, None)'
>>> help(os.path.join)
Help on function join in module ntpath:
join(a, *p)
Join two or more pathname components, inserting "\" as needed
只是
print obj.__doc__
或
myvar = obj.__doc__
帮助功能存在以交互方式查看帮助,它可以很容易地获取足够离不开它。
出于某种原因,我还忽略了,这通常与'pydoc.render_doc(obj)'的结果不同 - 我想知道在另一个函数内定义函数的情况下,通过设置func .__ doc__ = ...来设置它的文档字符串。 – EOL
您已经看到了参考文档字符串,魔术__doc__
变量持有的帮助身体:
def foo(a,b,c):
''' DOES NOTHING!!!! '''
pass
print foo.__doc__ # DOES NOTHING!!!!
为了得到一个函数的名称,你只需要使用__name__
:
def foo(a,b,c): pass
print foo.__name__ # foo
获取未构建函数的签名的方法可以使用func_code属性,并且可以从中读取其co_varnames:
def foo(a,b,c): pass
print foo.func_code.co_varnames # ('a', 'b', 'c')
我还没有找到如何做相同的内置函数。
其他答案可能是正确的,但这正是我所需要的。 – mathtick
@mathtick:现在这就是我所说的认真,在这么久之后接受一个答案! – kindall
哈...我想这是对stackoverflow界面的帮助,帮助我分散工作生活!我正在细读我的个人资料,实际上关注了我的问题列表,并注意到我忘记接受的一些内容。 – mathtick