通过实例调用方法失败

时间:2012-08-13 09:53:30

标签: 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, '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 个答案:

答案 0 :(得分:4)

你的缩进是愚蠢的,标签和空格混合在一起。使用python -tt进行验证。