I am trying to save form data, and I am wondering if I should use Python’s native pickle, or some sort of XML serializer. I wanted to use django’s serializers but these seem to be geared at working wit models, not regular Python dictionaries/objects.
The object I want to serialize would be composed almost entirely of strings (and possibly integers) and would look something like this:
data = {
'var1': "foo",
'var2': "bar",
'var3': ['bar', 'foo', 'moo', 'fish'],
'var4': 42
}
And I want to save this because I need to be able to render a HTML page based on these values at some point in the future.
Should I go ahead with saving the pickled object – or should I save it as XML? I don’t see any advantages of using XML, since I am not planning to access this outside of django. Am I making the wrong decision?
Few notes:
- This is not something I want to save in the session or cache, because I want to keep a history of these forms indefinitely
- The format/layout of the forms is subject to change so making a db schema to hold this information would be impractical.
What about json ? It’s lightweight, readable, portable, and the serialization/deserialization is dead simple for basic types (strings, ints, dicts, lists).
I try as hard as possible to stick to normalized db schemas, but for the few occasions where storing serialzed stuff is actually the “less worse” solution, I go for json, at least I can use my data with most programming languages.