Pickle class definition in module with dill
问题 My module contains a class which should be pickleable, both instance and definition I have the following structure: MyModule |-Submodule |-MyClass In other questions on SO I have already found that dill is able to pickle class definitions and surely enough it works by copying the definition of MyClass into a separate script and pickling it there, like this: import dill as pickle class MyClass(object): ... instance = MyClass(...) with open(..., 'wb') as file: pickle.dump(instance, file)