cPickle problem

Vojin Jovanovic vjovanov at stevens-tech.edu
Mon Apr 29 16:57:26 EDT 2002


I thought that cPickle can dump almost any kind of object, but it
doesn't work on this one


>>> import cPickle
>>> class foo:
 def __init__(self):
  self.e={'a':'4+5'}
 def __getattr__(self,arg):
  try:
   exec 'result =' + self.e[arg]
  except:
   return '#U'
  return result


>>> A=foo()
>>> A.a
9
>>> file=open('test','w')
>>> cPickle.dump(A,file)
Traceback (most recent call last):
  File "<pyshell#62>", line 1, in ?
    cPickle.dump(A,file)
TypeError: object of type 'string' is not callable


Any idea what is wrong?

Vin





More information about the Python-list mailing list