[Tutor] Pickling
ak@silmarill.org
ak@silmarill.org
Tue, 24 Jul 2001 17:58:17 -0400
On Tue, Jul 24, 2001 at 05:46:23PM -0400, Timothy M. Brauch wrote:
> I read the tutorial and I thought I actually understood what was going
> on, but appearently I didn't.
>
> I have some files whose contents are something like:
> [[1]]
> or
> [[1, 1], [2]]
> that is, lists of lists. I would like to access this data as lists of
> lists, which is where pickle comes in. But, I can't quite get it worked
> out. My interpreter session is as follows.
> ----------------------------------------------
> >>> import pickle
> >>> file=open('part_001.cyc')
> >>> data=pickle.load(file)
> Traceback (innermost last):
> File "<pyshell#12>", line 1, in ?
> data=pickle.load(file)
> File "c:\cs\tools\python20\lib\pickle.py", line 896, in load
> return Unpickler(file).load()
> File "c:\cs\tools\python20\lib\pickle.py", line 516, in load
> dispatch[key](self)
> KeyError: [
> >>>
> -----------------------------------------------------
pickle is something you first use to 'pickle' data into a file,
then read it from there. It has a special format for storing
the data.
In your case, look into eval() function.
--
Cymbaline: intelligent learning mp3 player - python, linux, console.
get it at: http://silmarill.org/cymbaline