How can I fix this error? When I try to load my save in with pickle it gives me this
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'
This is how I load/save
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)
First use 'wb'
instead of 'ab'
to have only last values
And later you can use
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)
or
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)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.