Hi, I'm trying to execute the following code:

d = {}
exec('import cPickle')  in d
desc = """
class A(object):
    pass
"""
exec(desc) in d

exec('a = A()') in d
exec('cPickle.dump(a, open("tmp.txt","wb"))')in d

for some reason it fails with the following traceback:

Traceback (most recent call last):
  File "pickleTest.py", line 10, in <module>
    exec('cPickle.dump(a, open("tmp.txt","wb"))')in d
  File "<string>", line 1, in <module>
cPickle.PicklingError: Can't pickle <class 'A'>: attribute lookup
__builtin__.A failed

pickle also dosen't work, changing protocol dosen't seem to help.

it works when i do:

exec('import __builtin__') in d
exec('__builtin__.A = A') in d

but it pollutes builtin namespace, which I don't like.

May be there is a workaround, how to do this correctly?
Thanks in advance,
Boris.
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to