通过网络发送字典 [英] Sending Dictionary via Network
问题描述
是否可以从Python程序发送非字符串对象
另一个?我特别需要将字典发送到另一个
程序。但是,使用套接字对象的send()
函数是不可能的。
帮助?
Buhi
mumebuhi写道:
是否可以从Python程序发送非字符串对象
另一个?我特别需要将字典发送到另一个
程序。但是,使用套接字对象的send()
函数是不可能的。
帮助?
Buhi
你需要先腌制它,然后在另一个
结束时取消它。除此之外,你应该可以发送它。
-Larry
mumebuhiaécrit:
是否可以从Python程序发送非字符串对象
另一个?我特别需要将字典发送到另一个
程序。但是,使用套接字对象的send()
函数是不可能的。
帮助?
>> d = dict(one = 1,two = three,question =" life,universe,and everything)
import simplejson
s = simplejson.dumps(d)
s
''{" question":" life,universe,and everything",two:"three,one:1}' '
>> simplejson.loads(s)== d
True
http://cheeseshop.python.org/pypi/simplejson
如果你真的*想要分享程序之间的对象,有办法
这样做(pyro浮现在脑海中)。但这变得更加复杂......
非常感谢您的回复。
可以直接使用socket进行pickle工作吗?我现在正在做的方式是
将对象挑选到一个文件然后通过
套接字发送文件内容。
Hi,
Is it possible to send a non-string object from a Python program to
another? I particularly need to send a dictionary over to the other
program. However, this is not possible using the socket object''s send()
function.
Help?
Buhi
mumebuhi wrote:Hi,
Is it possible to send a non-string object from a Python program to
another? I particularly need to send a dictionary over to the other
program. However, this is not possible using the socket object''s send()
function.
Help?
Buhi
You will need to pickle it first and unpickle it on the other
end. Other than that, you should be able to send it just fine.
-Larry
mumebuhi a écrit :Hi,
Is it possible to send a non-string object from a Python program to
another? I particularly need to send a dictionary over to the other
program. However, this is not possible using the socket object''s send()
function.
Help?
>>d = dict(one=1, two="three", question="life, universe, and everything")
import simplejson
s = simplejson.dumps(d)
s
''{"question": "life, universe, and everything", "two": "three", "one": 1}''
>>simplejson.loads(s) == d
True
http://cheeseshop.python.org/pypi/simplejson
If you *really* want to "share" objects between programs, there are way
to do so (pyro comes to mind). But this gets more complicated...
Thank you very much for the reply.
Can pickle work directly with socket? The way I am doing right now is
to pickle the object to a file then send the file content through the
socket.
这篇关于通过网络发送字典的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!