Python 通过实例调用方法失败
我已经完全放弃了这个荒谬的错误。这是我的密码:Python 通过实例调用方法失败,python,class,instance,attributeerror,method-invocation,Python,Class,Instance,Attributeerror,Method Invocation,我已经完全放弃了这个荒谬的错误。这是我的密码: class SaveGame: def __init__ (self): self.stats ={'strength':player.strength, 'dexterity':player.dexterity, 'inventory':player.inventory, 'read-inventory':player._inventory, 'equipped weapons':player.equippedweapons,
class SaveGame:
def __init__ (self):
self.stats ={'strength':player.strength, 'dexterity':player.dexterity, 'inventory':player.inventory, 'read-inventory':player._inventory, 'equipped weapons':player.equippedweapons, 'Consumable supply':procs.consum, 'Health':procs.health, 'poisoned?':procs.poison, 'storypointe':storypointe}
def save (self):
try:
with open (savefile, 'wb') as savebin:
pickle.dump (self.stats, savefile)
except KeyError:
print "Unable to load game"
sys.exit (0)
def load (self):
pickle.load (savefile)
现在,当我进入实施阶段时
startgame = raw_input ("Would you like to load your game or start a new one\n>>> ")
if startgame in ['load game', 'load my game', 'Load my game', 'Load game', 'load', 'Load']:
loadedgame = SaveGame ()
loadedgame.load ()
我得到这个错误:
Traceback (most recent call last):
File "<pyshell#1>", line 1, in <module>
import ModRpg
File "C:\Users\Sammu\The Folder\ModRpg.py", line 317, in <module>
loadedgame.load ()
AttributeError: SaveGame instance has no attribute 'load'
回溯(最近一次呼叫最后一次):
文件“”,第1行,在
导入ModRpg
文件“C:\Users\Sammu\The Folder\ModRpg.py”,第317行,在
LoadedName.load()
AttributeError:SaveGame实例没有属性“load”
缩进错误,制表符和空格混合在一起。使用python-tt
进行验证。通过“不帮助”你是说我错了,还是说你不喜欢我写的东西?他在帮助你,看起来是因为你的缩进不好,load()方法实际上嵌套在save()方法中,因此是AttributeError。哇,别再重复那些没完没了的代码了,伙计。你能把它简化成你的问题吗?查看有关代码块的编辑帮助。正如您在回答中所述,AttributeError:SaveGame实例没有属性“load”
是因为缩进不正确。如果你要求评论/帮助,你应该阅读评论/建议并实际行动。