参考链接:https://blog.csdn.net/u013810296/article/details/55509284

这里介绍下python自带的查看帮助功能,可以在编程时不中断地迅速找到所需模块和函数的使用方法

查看方法

通用帮助函数help()

python中的help()类似unix中的man指令,熟悉后会对我们的编程带来很大帮助

进入help帮助文档界面,根据屏幕提示可以继续键入相应关键词进行查询,继续键入modules可以列出当前所有安装的模块:

help> modules

Please wait a moment while I gather a list of all available modules...

AutoComplete        _pyio               filecmp             pyscreeze
AutoCompleteWindow _random fileinput pytweening
...... Enter any module name to get more help. Or, type "modules spam" to search
for modules whose name or summary contain the string "spam".

可以继续键入相应的模块名称得到该模块的帮助信息。 
这是python的通用的查询帮助,可以查到几乎所有的帮助文档,但我们很多时候不需要这样层级式地向下查询,接下来会介绍如何直接查询特定的模块和函数帮助信息。

例如要查询math模块的使用方法,可以如下操作:(输出的多行信息可通过q键退出)

>>> help(math)

  使用help(module_name)时首先需要import该模块,有些教程中不进行导入而在模块名中加入引号help('module_name'),这种方法可能会带来问题,大家可以用math模块测试,建议使用先导入再使用help()函数查询

查看内建模块sys.bultin_modulenames

>>> import sys
>>> sys.builtin_module_names
('_ast', '_bisect', '_codecs', '_codecs_cn', '_codecs_hk', ... 'zlib')
>>>

  

查询函数信息

查看模块下所有函数dir(module_name)

如我们需要列举出math模块下所有的函数名称,同样需要首先导入该模块

>>> dir(math)
['__doc__', '__loader__', '__name__',...]
>>>

  

查看模块下特定函数信息help(module_name.func_name)

注意

  func_name后面不要加(),因为python的语法默认加了括号后就运行函数

  相应的模块要导入

>>> help(math.sin)
Help on built-in function sin in module math: sin(...)
sin(x) Return the sine of x (measured in radians). >>>
#例2
>>> help(random.randint())
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: randint() missing 2 required positional arguments: 'a' and 'b'
>>> help(random.randint)
Help on method randint in module random: randint(a, b) method of random.Random instance
Return random integer in range [a, b], including both end points.

  

  

Python导入的包可以通过bagname.__all__查看所有方法但是这个有时不太好用,通过help(bagname.funcname)查看方法介绍

>>> help(random.seed)
Help on method seed in module random: seed(a=None, version=2) method of random.Random instance
Initialize internal state from hashable object. None or no argument seeds from current time or from an operating
system specific randomness source if available. If *a* is an int, all bits are used. For version 2 (the default), all of the bits are used if *a* is a str,
bytes, or bytearray. For version 1 (provided for reproducing random
sequences from older versions of Python), the algorithm for str and
bytes generates a narrower range of seeds.

  

Python 查看模块的帮助文档,方法和帮助信息的更多相关文章

  1. Python查看模块函数,查看函数方法的详细信息

    Python查看方法的详情 1.通用的帮助函数help() 使用help()函数来查看函数的帮助信息. 如: import requests help(requests) 会有类似如下输出: 2.查询 ...

  2. Python(文件、文件夹压缩处理模块,shelve持久化模块,xml处理模块、ConfigParser文档配置模块、hashlib加密模块,subprocess系统交互模块 log模块)

    OS模块 提供对操作系统进行调用的接口 os.getcwd() 获取当前工作目录,即当前python脚本工作的目录路径 os.chdir("dirname")  改变当前脚本工作目 ...

  3. Python处理PDF和Word文档常用的方法

    Python处理PDF和Word文档的模块是PyPDF2,使用之前需要先导入. 打开一个PDF文档的操作顺序是:用open()函数打开文件并用一个变量来接收,然后把变量给传递给PdfFileReade ...

  4. linux centos7 安装虚拟Python环境,pyenv安装文档

    python多版本控制pyenv安装文档 1.在线安装: curl -L https://github.com/pyenv/pyenv-installer/raw/master/bin/pyenv-i ...

  5. CentOS6.4下使用默认的文档查看器打开PDF文档乱码的解决方案

     最近在CentOS6.4下使用其默认的文档查看器打开PDF文档时出现乱码的方块,有两种方法可以解决.    方法一:修改/etc/fonts/conf.d/49-sansserif.conf文件,如 ...

  6. c语言小程序以及java生成注释文档方法

    c语言小程序:sizeof和strlen() sizeof运算符以字节为单位给出数据的大小,strlen()函数以字符为单位给出字符串的长度,字符和字节不是一回事. char类型用于存储字母和标点符号 ...

  7. Python学习笔记010——函数文档字符串

    函数文档字符串documentation string (docstring)是在函数开头,用来解释其接口的字符串.简而言之:帮助文档 包含函数的基础信息 包含函数的功能简介 包含每个形参的类型,使用 ...

  8. 使用Python爬虫库BeautifulSoup遍历文档树并对标签进行操作详解(新手必学)

    为大家介绍下Python爬虫库BeautifulSoup遍历文档树并对标签进行操作的详细方法与函数下面就是使用Python爬虫库BeautifulSoup对文档树进行遍历并对标签进行操作的实例,都是最 ...

  9. Nemo Documents – 给文件添加标签 以日历的形式将文件呈现出来,很像 Outlook,你可以根据年、月、日来查看不同类型的文档

    Nemo Documents – 给文件添加标签   scavin(Google+) on 2012.03.28. Nemo Documents 是款文件组织管理工具(文档管理器),不是街道大妈胜似大 ...

随机推荐

  1. docker研究-6 dockerfile 介绍使用

    Dockerfile是用来创建镜像的,首字母必须大写.

  2. Grafana数据迁移

    各系统和docker安装官方文档 https://grafana.com/grafana/download?platform=linux ubuntu安装相应版本的Grafana wget https ...

  3. JS高阶---进程与线程

    [大纲] 二级大纲: 三级大纲: [主体] (1)进程process 如下所示,两者内存空间相互独立 (2)线程thread (3)图解 注意:有的程序是多进程的,有的时单进程的 (4)单线程与多线程 ...

  4. Linux终端执行shell脚本,提示权限不够

    在学习dubbo过程中,上传自己写的脚本,执行的时候提示“权限不够”,从网上了解到是因为没有为脚本赋权限 解决方法是使用chmod命令为shell脚本赋予权限 chmod 777 ./service- ...

  5. maven配置阿里云国内仓库

    <mirror> <id>alimaven</id> <name>aliyun maven</name> <url>http:/ ...

  6. %STSADM% -o addsolution -filename AEMediaPlayerWebpart.wsp

    SET STSADM="c:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\bin\STSADM. ...

  7. redis 在 windows 中的安装

    redis 在 windows 中的安装 redis 官方并没有提供 redis 的 windows 版本.但是微软提供了 redis 的 windows 版本.有2.8和3.0版本.3.0版本支持集 ...

  8. 流媒体服务器 red5

    https://github.com/Red5/red5-server/releases/tag/v1.0.7-RELEASE   打开此链接  再tar包那里  复制链接地址 Wget此链接地址 W ...

  9. es启动失败

    Aug 09 21:43:23 10921114-elklogserver elasticsearch[30152]: 2018-08-09 21:43:23,068 main ERROR Null ...

  10. Linux基于FPM制作RPM包(以Nginx为例)

    1.搭建Epel  Yum源  安装在线yum源 [root@localhost ~]# rpm -ivh epel-release-latest-.noarch.rpm //安装扩展源 [root@ ...