Data Representation?
AK
ak at nospam.com
Sat Oct 11 19:51:11 EDT 2003
In article <abc3fdd3.0310111540.37400ed6 at posting.google.com>, Kris
Caselden wrote:
> Say I have some data:
>
>>>> a=[1]
>>>> b=[2]
>>>> link=[a,b]
>
> The simplest why to write this to a file represents it as
>
>>>> print str(link)
> [[1], [2]]
>
> Unfortunately, if this is read back in via execfile(), the whole
> dynamic nature of changing 'link' by changing 'a' and 'b' is lost. Is
> there any way to write data so that the list name is written instead
> of the list's values? Essentially, '[[a], [b]]' instead of '[[1],
> [2]]'? Any help most appreciated.
Sure, look at pickle and shelve modules in library reference.
shelve works kind of like this:
s = shelve.open('filename')
s['a'] = a
s.close()
s = shelve.open('filename')
a = s['a']
print a
code not tested..
-AK
More information about the Python-list
mailing list