__getattr__ and pickle

seanmcgrath at my-deja.com seanmcgrath at my-deja.com
Sun Jul 2 11:45:58 EDT 2000


At 09:07 02/07/00 -0400, Gordon McMillan wrote:
>
>Do you have a __getinitargs__ or __getstate__ or
__setstate__ that might be
>triggering a call to __getattr__?
>

I don't have calls to __getinitargs__,
__getstate__ or __setstate__.

What I do have is a __getattr__ which I suspect is
involved in this:-)

The patient is pyxie.py
(http://www.digitome.com/pyxie.py).
The object I am trying to pickle is a tree
structure.
A variable CurPos points to a sub-ordinate object
which can be of type xElement or xData.

The __getattr__ hook achieves a Delphi-like effect
in which attributes of these sub-ordinate objects
appear as attributes of the top level object.

It seemed like a good idea at the time:-)

Here is a test program that reproduces the
problem:-

from pyxie import *
try:
	import cPickle
	pickle = cPickle
except ImportError:
	import pickle

t = xTree()

s = pickle.dumps (t)
<!-- This works fine -->
print s
<!-- Boom!!! -->
t1 = pickle.loads(s)


When I try and pickle using the Python
implementation of pickle,
I get an exception:
	No attribute '__getstate__' on xTree or
current xNode.

I don't follow this as I thought __getstate__ was
for fine
tuning the information to be pickled.

Using cPickle I don't get an exception at save
time but
instead get a GPF at load time.


BTW, I have a test version of Pyxie with the
__getattr__
stuff taken out and it pickled just fine. Picked
versions
of parsed XML trees load really quickly with it.

What I am implementing is analagous to
Pythons .py/.pyc
idea. When Pyxie loads a tree it loads the binary
version unless the plain text version has been
modified more recently. When saving, it saves
both binary and plain text XML every time.
Works great!

>Does an Irishman like to talk?
>
Only on days that end in a "y":-)


regards,



Sent via Deja.com http://www.deja.com/
Before you buy.



More information about the Python-list mailing list