使用pickle为我的游戏创建保存/加载功能的问题(Python)

时间:2013-12-22 18:40:24

标签: python load save pickle

我正在尝试使用pickle为我的第一个基本游戏创建一个保存/加载功能,但我收到了错误。

我的代码是

def load():
    with open('save_game.dat', 'wb') as f:
        player_money,weed = pickle.load

我的追溯是

Traceback (most recent call last):

File "<string>", line 301, in runcode
File "<interactive input>", line 1, in <module>
File "C:\Users\Jake\Pictures\Documents\Blue Coat\Compooting\Weed Game.py", line 23, in load
player_money,weed = pickle.load
TypeError: 'builtin_function_or_method' object is not iterable

我将代码更改为包含(f)但我仍然收到此错误

Traceback (most recent call last):
  File "<string>", line 301, in runcode
  File "<interactive input>", line 1, in <module>
  File "C:\Users\Jake\Pictures\Documents\Blue Coat\Compooting\Weed Game.py", line 23, in load
    player_money,weed = pickle.load(f)
io.UnsupportedOperation: read

1 个答案:

答案 0 :(得分:0)

查看Python documentation on file modes - 在您的代码中,'wb'应该是'rb'。