注:本文基于Python 2.7.5编写
在linux上查看某个命令的使用可以使用man看用户手册,但是对于python的一些函数使用,却没办法使用man这个命令。但是也是有办法查询相应的帮助信息的,那就是用help的方式。
首先要进入python交互式环境,然后直接使用help(fun)的方式查看。
[root@CentOS-7-2 ~]# python
Python 2.7.5 (default, Nov 20 2015, 02:00:19)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> help(input)
接着就会出现input的帮助信息,
Help on built-in function input in module __builtin__:
input(...)
input([prompt]) -> value
Equivalent to eval(raw_input(prompt)).
使用help需要注意的是要分清内建函数和一些其他模块的方法,比如,查看列表list的append方法,就不能直接使用help(append),
>>> help(append)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'append' is not defined
>>>
需要使用help(list.append),
>>> help(list.append)
Help on method_descriptor:
append(...)
L.append(object) -- append object to end
关于内建函数可以参考以下链接:
https://www.runoob.com/python/python-built-in-functions.html
此外,对于一些第三方模块也需要导入后才能使用help查询帮助,
>>> from PIL import Image
>>> help(Image.save)
Help on function open in module PIL.Image:
open(fp, mode='r')
Opens and identifies the given image file.
......