查看Python包模块中的函数
2018-03-08 14:59
344 查看
在使用python的过程中有时需要import其他的包模块,而此时我们需要查看这个模块中提供了哪些函数,是否有像linux man一样可以查询的功能?在python中我们可以通过进入python控制台并导入相关的包模块,再使用help(模块名)来查看这个包模块的信息及相关的函数接口说明等。
以下已pycurl包举例说明用法:
1. 进入python 并导入包
root@ubuntu:/home/lvjc/myPython# python
Python 3.5.2 (default, Nov 23 2017, 16:37:01)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pycurl
>>>
2.通过help命令查看你需要man的函数
pydoc模块可以从python源码文件中获取docstring,然后生成帮助信息。
3.1 纯文本帮助信息
如在控制台输入命令 pydoc string 则会在控制台生成string的纯文本帮助信息。
root@ubuntu:/home/lvjc/myPython# pydoc string
Help on module string:
NAME
string - A collection of string operations (most are no longer used).
FILE
/usr/lib/python2.7/string.py
MODULE DOCS http://docs.python.org/library/string
DESCRIPTION
Warning: most of the code you see here isn't normally used nowadays.
Beginning with Python 1.6, many of these functions are implemented as
methods on the standard string object. They used to be implemented by
a built-in module called strop, but strop is now obsolete itself.
Public module variables:
whitespace -- a string containing all characters considered whitespace
lowercase -- a string containing all characters considered lowercase letters
uppercase -- a string containing all characters considered uppercase letters
letters -- a string containing all characters considered letters
digits -- a string containing all characters considered decimal digits
hexdigits -- a string containing all characters considered hexadecimal digits
:3.2 HTML帮助信息
pydoc还可以生成HTML格式的帮助信息,可以将HTML帮助信息生成到静态文本中,也可以启动一个Web服务器在线浏览帮助文档。root@ubuntu:/home/lvjc/myPython# pydoc -w string //在当前目录创建string.html文件
root@ubuntu:/home/lvjc/myPython# pydoc -p 5000 //启动一个web服务器监听 http://localhost:5000/
以下已pycurl包举例说明用法:
1. 进入python 并导入包
root@ubuntu:/home/lvjc/myPython# python
Python 3.5.2 (default, Nov 23 2017, 16:37:01)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pycurl
>>>
2.通过help命令查看你需要man的函数
>>> help(pycurl.Curl.getinfo) Help on method_descriptor: getinfo(...) getinfo(info) -> Result Extract and return information from a curl session. Corresponds to `curl_easy_getinfo`_ in libcurl, where *option* is the same as the ``CURLINFO_*`` constants in libcurl, except that the ``CURLINFO_`` prefix has been removed. (See below for exceptions.) *Result* contains an integer, float or string, depending on which option is given. The ``getinfo`` method should not be called unless ``perform`` has been called and finished. In order to distinguish between similarly-named CURLOPT and CURLINFO constants, some have ``OPT_`` and ``INFO_`` prefixes. These are ``INFO_FILETIME``, ``OPT_FILETIME``, ``INFO_COOKIELIST`` (but ``setopt`` uses ``COOKIELIST``!), ``INFO_CERTINFO``, and ``OPT_CERTINFO``. The value returned by ``getinfo(INFO_CERTINFO)`` is a list with one element per certificate in the chain, starting with the leaf; each element is a sequence of *(key, value)* tuples. Example usage:: import pycurl c = pycurl.Curl() c.setopt(pycurl.URL, "http://sf.net") c.setopt(pycurl.FOLLOWLOCATION, 1) c.perform() print c.getinfo(pycurl.HTTP_CODE), c.getinfo(pycurl.EFFECTIVE_URL) ... --> 200 "http://sourceforge.net/" Raises pycurl.error exception upon failure. .. _curl_easy_getinfo: http://curl.haxx.se/libcurl/c/curl_easy_getinfo.html (END)3. pydoc的用法:
pydoc模块可以从python源码文件中获取docstring,然后生成帮助信息。
3.1 纯文本帮助信息
如在控制台输入命令 pydoc string 则会在控制台生成string的纯文本帮助信息。
root@ubuntu:/home/lvjc/myPython# pydoc string
Help on module string:
NAME
string - A collection of string operations (most are no longer used).
FILE
/usr/lib/python2.7/string.py
MODULE DOCS http://docs.python.org/library/string
DESCRIPTION
Warning: most of the code you see here isn't normally used nowadays.
Beginning with Python 1.6, many of these functions are implemented as
methods on the standard string object. They used to be implemented by
a built-in module called strop, but strop is now obsolete itself.
Public module variables:
whitespace -- a string containing all characters considered whitespace
lowercase -- a string containing all characters considered lowercase letters
uppercase -- a string containing all characters considered uppercase letters
letters -- a string containing all characters considered letters
digits -- a string containing all characters considered decimal digits
hexdigits -- a string containing all characters considered hexadecimal digits
:3.2 HTML帮助信息
pydoc还可以生成HTML格式的帮助信息,可以将HTML帮助信息生成到静态文本中,也可以启动一个Web服务器在线浏览帮助文档。root@ubuntu:/home/lvjc/myPython# pydoc -w string //在当前目录创建string.html文件
root@ubuntu:/home/lvjc/myPython# pydoc -p 5000 //启动一个web服务器监听 http://localhost:5000/
相关文章推荐
- Python模块和函数帮助文档查看
- python查看模块,对象的函数方法
- Python模块和函数的快速查看
- 查看python的模块和函数帮助文档方法
- Python模块和函数的快速查看
- python查看模块,对象的函数
- Python正则匹配 -> 模块和基本函数
- [python] 第7章 函数 第8章 模块
- Python查看函数代码内容
- python_模块与函数学习笔记
- 03 Python 文件系统 访问权限 函数 类与面向对象 自定义模块
- python中不同模块(函数、类、变量)的调用
- 使用Python内置的模块与函数进行不同进制的数的转换
- python 函数、模块、包及import导入方法
- python查看模块的版本
- 洗礼灵魂,修炼python(11)--python函数,模块
- Python实现动态加载模块、类、函数的方法分析
- Python笔记5——匿名函数,偏函数,模块
- 一个月能入门Python吗?月薪25K的大佬给我整理了函数和模块资料
- Head First Python之2函数模块