0
Je python dict:Comment emballer python dict à XDR
data = {
'foo': 'bar',
'hello': 'world'
}
Comment puis-je emballer ce dict au format de données XDR?
Je python dict:Comment emballer python dict à XDR
data = {
'foo': 'bar',
'hello': 'world'
}
Comment puis-je emballer ce dict au format de données XDR?
Cela dépend vraiment de la façon dont vous voulez l'emballer. Comme key
value
paires, vous pouvez utiliser les éléments suivants:
import xdrlib
data = {'foo': 'bar', 'hello': 'world'}
p = xdrlib.Packer()
for key, value in data.items():
p.pack_string(key)
p.pack_string(value)
print p.get_buffer()
qui afficherait quelque chose comme:
◦◦◦foo◦◦◦◦bar◦◦◦◦hello◦◦◦◦◦◦world◦◦◦