我已经使用将数据读入的Python
def Save():
savefile = open('save.txt','w')
savefile.write(str(currentLocation)+'\n')
savefile.close()
print("GAME SAVED!", file=sys.stderr)
工作正常,但是当我去使用加载它...保存文件
def Load():
savefile = open('save.txt', 'r')
for line in savefile:
currentLocation.append(currentLocation)
savefile.close()
我得到所谓的错误:
AttributeError: 'int' object has no attribute 'append'.
任何理由你可以想到为什么这不起作用?
这意味着'currentLocation'是一个'int' - 而不是'list'。顺便说一句,你确定要'currentLocation.append(currentLocation)'(追加列表本身)?你可能想要的东西,如:'currentLocation.append(line)' – alfasin