problem pickling objects created with the type function

Greg Chapman glc at well.com
Fri Apr 23 07:34:26 EDT 2004


On 21 Apr 2004 14:57:17 -0700, danny_shevitz at yahoo.com (danny) wrote:

>I'm pretty sure the failure is because 'foobar' is never in the global
>namespace. If I change the code to foobar = type('foobar',...  then
>the code works, but I dont' want to do this because I create the class
>name in a factory and it is mangled to prevent different invocations
>of the factory from having the same class name.
>
>Does anyone know how to get around this, or how to get 'foobar' =
>childType into the global namespace?

You should be able to make foobars pickleable without introducing foobar into
the global namespace by using a __reduce__ method, see:

http://www.python.org/peps/pep-0307.html

expecially the section "Extended __reduce__ API".

---
Greg Chapman




More information about the Python-list mailing list