查看两个模块的文档.
_socket是在链接库里的.也就是说这不是用python实现的,是socket操作的C实现,这个是非常底层的操作.socket.py是用py代码把C实现的模块的封装起来之后的模块,供人使用.
在不同系统_socket的位置不一样,你可以具体去看,然后想看源码的话就要去直接看未编译的python源码,才能看到_socket的代码.
In [3]: _socket?
Type: module
String form:
File: /usr/lib64/python2.7/lib-dynload/_socketmodule.so
Docstring:
Implementation module for socket operations.
See the socket module for documentation.In [5]: socket?
Type: module
String form:
File: /usr/lib64/python2.7/socket.py
Docstring:
This module provides socket operations and some related functions.
On Unix, it supports IP (Internet Protocol) and Unix domain sockets.
On other systems, it only supports IP. Functions specific for a
socket are available as methods of the socket object.