2017-02-02 67 views
0

我该如何解决这个错误?当我尝试加载我保存在与泡菜它给了我这个Python 2 - TypeError:int()参数必须是字符串,类似字节的对象或数字,而不是'list'

Traceback (most recent call last): 
    File "C:\Users\user\Downloads\game.py", line 315, in <module> 
    menu() 
    File "C:\Users\user\Downloads\game.py", line 261, in menu 
    if (0) > int(hunger) or (0) > int(thirst): 
TypeError: int() argument must be a string, a bytes-like object or a number, not 'list' 

这是我如何加载/保存

with open('objs.pickle', "rb") as f: 
    money = pickle.load(f) 
    hunger = pickle.load(f) 
    thirst = pickle.load(f) 
    energy = pickle.load(f) 
    wanted = pickle.load(f) 
    gun = pickle.load(f) 


with open('objs.pickle', 'ab') as f: 
    pickle.dump([money, hunger, thirst, energy, gun, wanted], f) 
+0

总是在** QUESTION **中放入** FULL **错误信息。还有其他有用的信息。 – furas

+0

我在那里编辑它 – Cube

+0

使用'print(饥饿,渴望)'来看看你在这个变量中有什么。 – furas

回答

0

首先使用'wb'代替'ab'到只有最后的值

稍后可以使用

with open('objs.pickle', "rb") as f: 
    money = pickle.load(f) 
    hunger = pickle.load(f) 
    thirst = pickle.load(f) 
    energy = pickle.load(f) 
    gun = pickle.load(f) 
    wanted = pickle.load(f) 


with open('objs.pickle', 'wb') as f: 
    pickle.dump(money, f) 
    pickle.dump(hunger, f) 
    pickle.dump(thirst, f) 
    pickle.dump(energy, f) 
    pickle.dump(gun, f) 
    pickle.dump(wanted, f) 

with open('objs.pickle', "rb") as f: 
    money, hunger, thirst, energy, gun, wanted = pickle.load(f) 

with open('objs.pickle', 'wb') as f: 
    pickle.dump([money, hunger, thirst, energy, gun, wanted], f) 
+0

它的工作表示感谢 – Cube

相关问题