[Tutor] Nested Lists / Array Module

Danny Yoo dyoo at hkn.eecs.berkeley.edu
Tue Oct 21 20:54:28 EDT 2003



On Wed, 22 Oct 2003 Harm_Kirchhoff at mail.digital.co.jp wrote:

> Python supports nested lists, which is very nice and can be used for very
> simple databases.
>
> However, I could not find a way to write nested lists to files &
> retrieve them easily. The .writelines() method expects a string as an
> argument.
>
> Is there a method to dump any list on disk & read it back, or is it
> necessary to code this task ?


Hi Harm,

Yes.  For simple cases, the 'shelve' module can help to "serialize"
these nested structures to and from disk.  "Serialization" is a term we
use to transform arbitrary Python objects to byte strings, and it's pretty
easy to do in Python.

In fact, we talked about this about a week ago:

    http://mail.python.org/pipermail/tutor/2003-October/025741.html

The example at that link uses only a flat list, but 'shelve' should work
with lists in lists too.


If you have more questions, please feel free to ask.  Good luck!




More information about the Tutor mailing list