dict but with a __getattr__ and I'm getting pickling errors.
This works but is not good enough.
$ python2.4
.... pass>>import cPickle as pickle
class Dict(dict):
....
{'age': 40, 'name': 'Zahid'}>>>
friend = Dict(name='Zahid', age=40)
friend
{'age': 40, 'name': 'Zahid'}>>v=pickle.dumps(friend)
p=pickle.loads(v)
p
This is what happens when I'm trying to be clever:
.... def __getattr__(self, key):>>import cPickle as pickle
class Dict(dict):
.... return self.__getitem__(key)
....
{'age': 40, 'name': 'Zahid'}>>friend = Dict(name='Zahid', age=40)
friend
'Zahid'>>friend.name
Traceback (most recent call last):>>v=pickle.dumps(friend)
File "<stdin>", line 1, in ?
File "/usr/lib/python2.4/copy_reg.py", line 73, in _reduce_ex
getstate = self.__getstate__
File "<stdin>", line 3, in __getattr__
KeyError: '__getstate__'
Why can't I pickle the slightly more featurefull class there called
'Dict'? I've got my reasons for not going for a simple type dict but
feel that that is irrelevant right now.