pickle导入文件报错AttributeError: Can‘t get attribute ‘XXX‘ on <module ‘__main__‘ from处理

class CustomUnpickler(pickle.Unpickler):

    def find_class(self, module, name):
        try:
            return super().find_class(__name__, name)
        except AttributeError:
            return super().find_class(module, name)

pickle_data = CustomUnpickler(open(path, 'rb')).load()

你可能感兴趣的:(python,os)