Python发送字典通过TCP [英] Python sending dictionary throught TCP
本文介绍了Python发送字典通过TCP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是一个python初学者,我很好奇我如何通过TCP发送一个字典$ /
I'm a python beginner, and I'm curious how can I send a dictionary through TCP
推荐答案
你应该将其与 pickle
序列化:/ p>
You should serialize it with pickle
:
import pickle
dict = {...}
tcp_send(pickle.dumps(dict))
另一端:
import pickle
dict = pickle.loads(tcp_recieve())
如果另一端未写入python,则可以使用数据序列化格式,例如 xml , json 或 yaml 。
If the other end is not written in python, you can use a data serialization format, like xml, json or yaml.
这篇关于Python发送字典通过TCP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文