[Tutor] Re: Nested Lists / Array Module
Shantanoo Mahajan
python at dhumketu.cjb.net
Wed Oct 22 06:57:59 EDT 2003
+-- Harm_Kirchhoff at mail.digital.co.jp [python-tutor] [22-10-03 05:37 IST]:
| 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 ?
|
| The array module seems to have such method, however, I could not find
| sufficient code examples to understand how the array module works. The
| Python Library Reference mentions the .fromfile() and .tofile() methods,
| does anyone have experience with the array module, especially whether it
| allows to write & retrieve nested arrays without problems ? Could you pass
| me some sample code ?
|
|
| Harm
import pickle
f=open('test','w+')
a=[[1,2,3,4],[1,2,[123]]]
pickle.dump(a,f)
f.seek(0)
b=pickle.load(f)
print a,b
--
With Best Regards,
Shantanoo Mahajan
More information about the Tutor
mailing list