[英]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)
First use 'wb'
instead of 'ab'
to have only last values 首先使用'wb'
而不是'ab'
仅具有最后一个值
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)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.