这是我的代码
#my process class----------
class Process(object):
def PrintName(self, name):
print('Your name is : ', name)
#pickling-------------
import pickle
model = Process()
filename = 'Process.pkl'
pickle.dump(model, open(filename, 'wb'))
#loading the pickle-------------
model = pickle.load(open('Process.pkl', 'rb'))
当我在jupyter笔记本上运行以上代码时,出现错误AttributeError:'module'对象没有属性'Process', 混淆哪一行会导致错误
任何帮助将不胜感激
答案 0 :(得分:1)
在Python中,缩进很重要。 由于缩进错误,函数之后的所有内容仍然属于Process类。
您可以阅读有关python here的缩进和编码样式的更多信息
我已根据PEP8格式化了您的代码,它现在可以正常工作了:
import pickle
# my process class----------
class Process(object):
def PrintName(self, name):
print('Your name is : ', name)
# pickling-------------
model = Process()
filename = 'Process.pkl'
pickle.dump(model, open(filename, 'wb'))
# loading the pickle-------------
model = pickle.load(open('Process.pkl', 'rb'))