pydoc 和 help() 之间的区别?
这两件事有不同吗?两者在Python中给出的结果是相似的。
Are these two things different? The results that the two give in Python are similar.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
help()
是一个 Python 函数。pydoc 是同一事物的命令行界面。
如果您想了解 pydoc 的更多功能,请查看 pydoc.py (
import pydoc; pydoc.__file__
) 并查看cli
函数中的内容。它确实做了一些额外的导入魔法,但我不认为它真的需要 -help()
接受一个以相同方式评估的字符串,所以如果你有“foo.py” ",运行python
并执行help('foo')
它会得到与import foo; 几乎相同的结果。我认为,help(foo)
会的,只是布局上有细微的差别。大概有历史原因吧。简而言之,
pydoc foo
大约等于python -c "help('foo')"
help()
is a Python function.pydoc
is a command-line interface to the same thing.If you want to see more what pydoc does, take a look in pydoc.py (
import pydoc; pydoc.__file__
) and see what's in thecli
function. It does do some extra importing magic, but I don't think it really needs to -help()
accepts a string which is evaluated in the same sort of way, so if you have "foo.py", runpython
and dohelp('foo')
it'll get just about the same result asimport foo; help(foo)
would, just with minor differences in layout, I think. Probably historical reasons there.In short,
pydoc foo
is about equal topython -c "help('foo')"
交互式
help
函数仅导入 pydoc。从源代码中:注意 __call__ 定义。
您可以使用
help(help)
查看文档;-)您可以在下次好奇时使用
inspect
模块自行检查源代码。如果您想自己调查,以下内容将返回为对象定义的模块的源代码定义:
The interactive
help
function just imports pydoc. From the source:Note the
__call__
definition.You can see the documentation with
help(help)
;-)You can use the
inspect
module to check out the source yourself next time you're curious.In case you want to investigate on your own, the following will return the source code definition of the module defined for an object:
简而言之,我认为 pydocs 可以解释为 Tesla, Inc.,而 help 只是 tesla 的产品,就像 Tesla Model S 一样
如果进入
help
函数代码,就会清楚地提到帮助正在使用pydocs.help
pydocs
有更多选项与help
相比的功能In simple words I think
pydocs
can be explained as Tesla, Inc. andhelp
is just a product of tesla like Tesla Model SIf one goes inside the
help
function code it is clearly mentioned that help is usingpydocs.help
pydocs
has got many more options and features as compared tohelp