from socket import *
self.clientSock = socket(AF_INET, SOCK_STREAM)
self.clientSock.connect(ADDR)
self.clientSock.send(bytes(str(len(message)), “utf-8”))
上述三句在python3上运行良好
-------------------------------------
转到python2.7的时候,发现bytes变成了一个关键字
self.clientSock.send(bytes(str(len(message)), ”utf-8“))
报错:
self.clientSock.send(bytes(str(len(message)), “utf-8”))
TypeError: str() takes at most 1 argument (2 given)
使用:self.clientSock.send(bytes(message))能够发送,但是发送的不是bytes了貌似
-----------------------------------
python2.7:
x = self.clientSock.send(bytes(str(len(message))))
print(x) ----- x = 2
python3.4:
x = self.clientSock.send(bytes(str(len(message)), “utf-8”))
print(x) ----- x = 1
---求解,怎么在python2.7上达到python3.4上一样的效果呢?
self.clientSock = socket(AF_INET, SOCK_STREAM)
self.clientSock.connect(ADDR)
self.clientSock.send(bytes(str(len(message)), “utf-8”))
上述三句在python3上运行良好
-------------------------------------
转到python2.7的时候,发现bytes变成了一个关键字
self.clientSock.send(bytes(str(len(message)), ”utf-8“))
报错:
self.clientSock.send(bytes(str(len(message)), “utf-8”))
TypeError: str() takes at most 1 argument (2 given)
使用:self.clientSock.send(bytes(message))能够发送,但是发送的不是bytes了貌似
-----------------------------------
python2.7:
x = self.clientSock.send(bytes(str(len(message))))
print(x) ----- x = 2
python3.4:
x = self.clientSock.send(bytes(str(len(message)), “utf-8”))
print(x) ----- x = 1
---求解,怎么在python2.7上达到python3.4上一样的效果呢?