Reputation: 9422
I have a python list as
[
(A,{'a':1,'b':2,'c':3,'d':4}),
B,{'a':1,'b':2,'c':3,'d':4}),
...
]
I want to know if there is a standard library of serializing this kind of list to xml or should I hand code it to a file.
Edit : Added Detail
Assuming this is used to construct a message such that
message = A( Feild attributes{'a':1,'b':2,'c':3,'d':4}) || B Field attributes{'a':1,'b':2,'c':3,'d':4}) || C Field attributes{'a':1,'b':2,'c':3,'d':4})
Upvotes: 0
Views: 382
Reputation: 1410
"use json/yaml/whitespace" comments aside (I suppose you have your reasons to do so, instead go for pickle/json),
you can try the very pythonic elementtree library (in the standardlib), or even use some advice from google : search "converting python dictionary to xml"
(not to sound too rude .. take it with a wink)
looking at your example, what are A and B ? integers ? strings ? classmethods ?
Upvotes: 2
Reputation: 76753
Upvotes: 1
Reputation: 42825
Does it need to be XML? This is the usual domain of the pickle
module.
But, no, there's no standard serialize-Python-object-to-XML library. (I have one I wrote a while ago, it's not published, much less "standard".) There are libraries like lxml
for converting XML to Python objects and back, and the usual sax
, dom
, and expat
libraries for reading XML.
Upvotes: 4