我有这个代码
class HNCS (ThreadingTCPServer):
def verify_request(self, request, client_address):
for key in connections:
if connections[key].client_address[0] == client_address[0]:
if client_address[0] != '127.0.0.1':
return False
return True
def welcome(self):
return '''______________________________________________________
------------------------------------------------------
%s
______________________________________________________
------------------------------------------------------
* Server started %s
* Waiting for connections on port %i
''' % (gpl, ctime(), PORT)
我只是想不通它说的那一行 如果连接[key].client_address[0] == client_address[0]
为什么我们在字典后面使用 client_address 作为属性???
最佳答案
也许字典正在存储恰好具有 client_address 成员属性的对象的值?
换句话说,.client_address
与作为参数传入的 client_address
不是相同的东西。相反,它是恰好存储在 connections[key]
中的类中字段的名称。
关于python - 关于 python 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2741440/