import pickle
class NoClass():
def __init__(self, name, level, cls, time_played):
self.name = name
self.level = level
self.cls = cls
self.time_played = time_played
def Write_char_file(registered_username):
avatar = NoClass('',1,'',0) #--------i am trying to pickle and write this
a = str('Characters\%s.txt' % registered_username) #---- the saving file
f = open(a, 'wb')
f.write(pickle.dumps(avatar))
f.close()
def Asign_to_slot(char_lst):
pass
Asign_to_slot(Write_char_file('my_name'))
当尝试在bge中运行它时,当我使用python IDLE运行它时,它会引发该错误,但没有问题,尽管我知道通常无法对这些类进行腌制,但我还是设法在文件中写入了腌制的类,然后我什至可以管理打开文件,解开文件并打印类的属性
"_pickle.PicklingError: Can't pickle <class '__main__.NoClass'>: attribute lookup NoClass on __main__ failed"
白板的微信
相关分类