I\'ve recently changed my program\'s directory layout: before, I had all my modules inside the \"main\" folder. Now, I\'ve moved them into a directory named after the progra
This can be done with a custom "unpickler" that uses find_class():
import io
import pickle
class RenameUnpickler(pickle.Unpickler):
def find_class(self, module, name):
renamed_module = module
if module == "tools":
renamed_module = "whyteboard.tools"
return super(RenameUnpickler, self).find_class(renamed_module, name)
def renamed_load(file_obj):
return RenameUnpickler(file_obj).load()
def renamed_loads(pickled_bytes):
file_obj = io.BytesIO(pickled_bytes)
return renamed_load(file_obj)
Then you'd need to use renamed_load() instead of pickle.load() and renamed_loads() instead of pickle.loads().