pydoc 和 help() 之间的区别?

发布于 2024-11-18 14:05:09 字数 36 浏览 2 评论 0原文

这两件事有不同吗?两者在Python中给出的结果是相似的。

Are these two things different? The results that the two give in Python are similar.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

记忆之渊 2024-11-25 14:05:09

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 the cli 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", run python and do help('foo') it'll get just about the same result as import foo; help(foo) would, just with minor differences in layout, I think. Probably historical reasons there.

In short, pydoc foo is about equal to python -c "help('foo')"

归属感 2024-11-25 14:05:09

交互式 help 函数仅导入 pydoc。从源代码中:

class _Helper(object):                                 
    """Define the builtin 'help'.                      
    This is a wrapper around pydoc.help (with a twist).

    """                                                

    def __repr__(self):                                
        return "Type help() for interactive help, " \  
               "or help(object) for help about object."
    def __call__(self, *args, **kwds):                 
        import pydoc                                   
        return pydoc.help(*args, **kwds)  

注意 __call__ 定义。

您可以使用 help(help) 查看文档;-)

您可以在下次好奇时使用 inspect 模块自行检查源代码。

如果您想自己调查,以下内容将返回为对象定义的模块的源代码定义:

inspect.getsource(inspect.getmodule(help))

The interactive help function just imports pydoc. From the source:

class _Helper(object):                                 
    """Define the builtin 'help'.                      
    This is a wrapper around pydoc.help (with a twist).

    """                                                

    def __repr__(self):                                
        return "Type help() for interactive help, " \  
               "or help(object) for help about object."
    def __call__(self, *args, **kwds):                 
        import pydoc                                   
        return pydoc.help(*args, **kwds)  

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:

inspect.getsource(inspect.getmodule(help))
物价感观 2024-11-25 14:05:09

简而言之,我认为 pydocs 可以解释为 Tesla, Inc.,而 help 只是 tesla 的产品,就像 Tesla Model S 一样

如果进入 help 函数代码,就会清楚地提到帮助正在使用 pydocs.help

"""
Define the built-in 'help'.
    This is a wrapper around pydoc.help (with a twist).
"""

pydocs 有更多选项与 help 相比的功能

In simple words I think pydocs can be explained as Tesla, Inc. and help is just a product of tesla like Tesla Model S

If one goes inside the help function code it is clearly mentioned that help is using pydocs.help

"""
Define the built-in 'help'.
    This is a wrapper around pydoc.help (with a twist).
"""

pydocs has got many more options and features as compared to help

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文