import pickle
class Cucumber:
def __init__(self):
self.size = 'small'
def get_size(self):
return self.size
cucu = Cucumber()
with open('cucumber.pckl', 'wb') as file_out:
pickle.dump(cucu,file_out)
"""
import pickle
with open('cucumber.pckl', 'rb') as file_in:
data = pickle.load(file_in)
print(type(data))
print(data)
print(data.size)
print(data.get_size())
"""
"""
上面那段是输入,下面那段是输出,输出的时候报错,
报错信息:data = pickle.load(file_in)
AttributeError: Can't get attribute 'Cucumber' on <module '__main__' (built-in)>
请问怎么修改
object,functions and class can be pickled, 为什么还会报错?