-1

我有这个完全荒谬的错误,我已经完全放弃了。这是我的代码:

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'
4

1 回答 1

4

您的缩进是错误的,混合了制表符和空格。用于python -tt验证。

于 2012-08-13T09:55:01.317 回答