[Tutor] Pickling

Suzanne Little s349929@student.uq.edu.au
Thu, 29 Mar 2001 10:57:06 +1000 (GMT+1000)


On Tue, 27 Mar 2001, Daniel Yoo wrote:
>
> Ah!  Most likely, you'll need to import the minidom class; pickle assumes
> that the class is in Python's memory before you unpickle stuff.  The
> problem about unpickling is that Python needs to know what the minidom
> class looks like --- and it's restricted from automatically loading
> classes, so that's why it's confused.
>
> This is a common error, so don't worry about it.  If you do the line:
>
>     from xml.dom import minidom

Thanks for your reply Daniel.

What you've said makes sense and re-reading the documentation I
can see what it means. Unfortunately this doesn't seem to be working in
this case and I'm thoroughly confused.

At the end of this message is a session showing what happened. Basically
I'm getting the same error message regardless of importing and if I try it
again (without changing anything) I get all sorts of different messages.

I'm getting the feeling that pickle may not really work for what I'm
aiming at. :( Even if I can get this simple example to work, I'm still
getting different errors when I try to pickle.dump bigger xml files. I'm
getting ready to move on and try something else but I'd like to work out
why this isn't working so I'll keep picking at it.

Thanks for any suggestions,
Suzanne

Python 2.0 (#1, Feb 14 2001, 10:51:28)
[GCC 2.95.2 19991024 (release)] on sunos5
Type "copyright", "credits" or "license" for more information.
>>> import pickle
>>> from xml.dom import minidom
>>> f = open('pickleTest')
>>> pickle.load(f)
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "/usr/local/stow/python-2.0/lib/python2.0/pickle.py", line 896, in
load
    return Unpickler(file).load()
  File "/usr/local/stow/python-2.0/lib/python2.0/pickle.py", line 516, in
load
    dispatch[key](self)
KeyError:

>>> pickle.load(f)  #because I have unerring faith that maybe I looked at
		    #it wrong....
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "/usr/local/stow/python-2.0/lib/python2.0/pickle.py", line 896, in
load
    return Unpickler(file).load()
  File "/usr/local/stow/python-2.0/lib/python2.0/pickle.py", line 516, in
load
    dispatch[key](self)
  File "/usr/local/stow/python-2.0/lib/python2.0/pickle.py", line 797, in
load_put
    self.memo[self.readline()[:-1]] = self.stack[-1]
IndexError: list index out of range
>>>

This second, different error occurs regardless of what I load. Even if I
don't load the minidom.

If I try it again (why not! :)
>>> pickle.load(f)
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "/usr/local/stow/python-2.0/lib/python2.0/pickle.py", line 896, in
load
    return Unpickler(file).load()
  File "/usr/local/stow/python-2.0/lib/python2.0/pickle.py", line 516, in
load
    dispatch[key](self)
KeyError: 7
>>>
Trying it once more shows a different message again (similar to the
second but about self.stack). Then another different message and so on
and so on. I'm going to stop now. :)

--------------------------------------------------------------------------
"Contrariwise," continued Tweedledee, "If it was so, it might be; and if
it were so, it would be; but as it isn't, it ain't.  That's logic"
                             -Lewis Carroll
--------------------------------------------------------------------------