繁体   English   中英

如何找到python模块的功能?

[英]How can I find the function of a python module?

我正在使用OpenCV,我想看看“矩形”功能是什么。 我可以使用dir(module)函数来获取函数定义和名称,但是我不知道如何查看实际函数。 我正在使用Linux(Ubuntu 16.04),并且想知道这些库是否在“ / usr / local /”或其他位置。 OpenCV cv2 python库只是一个示例,我想知道如何查看导入到python中的库的任何功能。

有多种方法:

我建议您使用精彩的IPython交互式外壳。

您可以通过添加两个问号来查看任何函数(或通常具有源代码的任何对象)的定义?? 以它的名字。 以下是在我的终端上运行的简短示例:

$ ipython
Python 2.7.9 (default, Jan 27 2016, 11:42:08) 
Type "copyright", "credits" or "license" for more information.

IPython 2.3.1 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.

In [1]: import urllib

In [2]: urllib.urlopen??
Type:        function
String form: <function urlopen at 0x2b56465ac578>
File:        /sw/python/2.7.9/Linux.x86_64/lib/python2.7/urllib.py
Definition:  urllib.urlopen(url, data=None, proxies=None)
Source:
def urlopen(url, data=None, proxies=None):
    """Create a file-like object for the specified URL to read from."""
    from warnings import warnpy3k
    warnpy3k("urllib.urlopen() has been removed in Python 3.0 in "
             "favor of urllib2.urlopen()", stacklevel=2)

    global _urlopener
    if proxies is not None:
        opener = FancyURLopener(proxies=proxies)
    elif not _urlopener:
        opener = FancyURLopener()
        _urlopener = opener
    else:
        opener = _urlopener
    if data is None:
        return opener.open(url)
    else:
        return opener.open(url, data)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM