Cube Cube - 4 years ago 285
Python Question

Python 2 - TypeError: int() argument must be a string, a bytes-like object or a number, not 'list'

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)

Answer Source

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)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download