python如何查看函数功能,类似于linux下的man


[root@iZ94gh8l046Z python]# python
Python 2.7.5 (default, Jun 17 2014, 18:11:42) 
[GCC 4.8.2 20140120 (Red Hat 4.8.2-16)] on linux2
Type help, copyright, credits or license for more information.
>>> import socket
>>> help(socket.gethostname)
Help on built-in function gethostname in module _socket:

gethostname(...)
    gethostname() -> string
    
    Return the current host name.

>>> help(socket.gethostbyname) 
Help on built-in function gethostbyname in module _socket:

gethostbyname(...)
    gethostbyname(host) -> address
    
    Return the IP address (a string of the form '255.255.255.255') for a host.

>>> 

说明:

import socket:导入python提供的一个核心网络库

help(socket.gethostname):查看帮助信息

gethostname:没有参数,返回所在主机或本地主机的名字

gethostbyname:接收一个参数hostname,返回对应的IP

 

 

评论关闭