|
Well, in Python a class definition is an object. But class objects tend to have complications associated with them. Pickling a normal object instance is just a matter of looking at its __dict__ and then turning all its variables into strings. Pickling a class would involve including Python bytecode as well, which is somewhat harder.
Setting __getstate__ and __setstate__ on an object overrides Pickle's default serialization and deserialization routines, allowing you to define manually how your object is turned into a string. Other than that, you could play around with the code and code.compile modules, but they tend to be rather sparse on documentation.
Is there a reason you really need to pickle a class? Could it not conceivably be done another way?
|