2017-02-02 103 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

相關問題