Recursive loading trouble for immutables
steve at REMOVE-THIS-cybersource.com.au
Sat Nov 24 00:19:20 CET 2007
On Fri, 23 Nov 2007 16:43:28 -0600, rekkufa wrote:
> I am currently building a system for serializing python objects to a
> readable file-format, as well as creating python objects by parsing the
> same format.
You mean like pickle? (Pardon me for telling you something you may
already know, but then you may not already know it...)
>>> import pickle
>>> # Create a recursive tuple.
... alist = [1, 2, 3]
>>> atuple = (4, 5, alist)
(4, 5, [1, 2, 3, (4, 5, [...])])
pickle can dump to files, using either text or binary protocols, and load
objects back from either files or strings. I won't pretend the text
protocol is exactly human readable, but perhaps the way forward is to
write a post-processor to convert the output of pickle to something more
human-readable, rather than writing a completely new serializer.
More information about the Python-list