我有以下代码来自 wesley chun 的核心 python 应用程序编程书
#!/usr/bin/env python
"""
tcp server
"""
from socket import AF_INET, SOCK_STREAM, socket
from time import ctime
HOST = ''
PORT = 21567
BUFSIZE = 1024
ADDR = (HOST, PORT)
tcp_server_socket = socket(AF_INET, SOCK_STREAM)
tcp_server_socket.bind(ADDR)
#maximum number of incoming connection before connection is refused
tcp_server_socket.listen(5)
while True:
print "waiting for connection"
tcpCliSock, addr = tcp_server_socket.accept()
print "... connected from:" , addr
while True:
DATA = tcpCliSock.recv(BUFSIZE)
if not DATA:
break
tcpCliSock.send('[%s] %s' % (ctime(), DATA))
tcpCliSock.close()
tcp_server_socket.close()
我对原始代码进行了一些修改,但是我仍然很困惑如何最好地修改它以使其更合规
这是我收到的所有消息
C: 14,0: Invalid name "tcp_server_socket" (should match (([A-Z_][A-Z0-9_]*)|(__.*__))$)
C: 21,4: Invalid name "tcpCliSock" (should match (([A-Z_][A-Z0-9_]*)|(__.*__))$)
C: 21,16: Invalid name "addr" (should match (([A-Z_][A-Z0-9_]*)|(__.*__))$)
E: 25,15: Instance of '_socketobject' has no 'recv' member
E: 28,8: Instance of '_socketobject' has no 'send' member
我想前三个只是想让我使用所有大写变量名称,这是这些类型脚本的标准做法,我没有看到使用这种约定使代码变得更具可读性,相反它看起来不那么可读,什么是 pylint 中这种规则背后的动机以及如何使代码更兼容,我几乎不认为这种地位的作者会无缘无故地编写这样的代码,无论是可读性、初学者友好性还是其他任何东西。