Python - converting sock.recv to string

前端 未结 2 435
时光说笑
时光说笑 2020-12-06 06:09

I\'m digging around with python and networking.

while True:
   data = sock.recv(10240)

This is definitely listening. But it seems to need

2条回答
  •  广开言路
    2020-12-06 06:32

    In Python 2.7.x and before, data is already a string. In Python 3.x, data is a bytes object. TO convert bytes to string, use the decode() method. decode() will require a codec argument, like 'utf-8'.

提交回复
热议问题