简体   繁体   English

Python 2-TypeError:int()参数必须是字符串,类似字节的对象或数字,而不是“列表”

[英]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.

相关问题 int()参数必须是字符串,类似字节的对象或数字,而不是“列表” - int() argument must be a string, a bytes-like object or a number, not 'list' 如何在python中将图像列表转换为数字列表? TypeError:int()参数必须是字符串,类似字节的对象或数字,而不是“ Image” - How to convert list of images into list of numbers in python? TypeError: int() argument must be a string, a bytes-like object or a number, not 'Image' Django TypeError:int()参数必须是字符串,类似字节的对象或数字,而不是&#39;list&#39; - Django TypeError: int() argument must be a string, a bytes-like object or a number, not 'list' 类型错误:int() 参数必须是字符串、类似字节的对象或数字,而不是“列表” - TypeError: int() argument must be a string, a bytes-like object or a number, not 'list' TypeError at /students/exam/1/ int() 参数必须是字符串、类似字节的对象或数字,而不是“列表” - TypeError at /students/exam/1/ int() argument must be a string, a bytes-like object or a number, not 'list' 类型错误:int() 参数必须是字符串、类似字节的对象或数字,而不是“列表”? - TypeError: int() argument must be a string, a bytes-like object or a number, not 'list'? 错误测试python代码:TypeError:int()参数必须是字符串,类似字节的对象或数字,而不是“ NoneType” - Error testing python code: TypeError: int() argument must be a string, a bytes-like object or a number, not 'NoneType' TypeError : int() 参数必须是字符串、类似字节的对象或数字,而不是 Python Tkinter 中的“条目” - TypeError : int() argument must be a string, a bytes-like object or a number, not 'Entry' in Python Tkinter TypeError: int() 参数必须是字符串、类似字节的对象或数字,而不是 python3 中的“NoneType”错误 - TypeError: int() argument must be a string, a bytes-like object or a number, not 'NoneType' error in python3 类型错误:将形状转换为 TensorShape 时出错:int() 参数必须是字符串、类似字节的对象或数字,而不是“元组”。 在蟒蛇 - TypeError: Error converting shape to a TensorShape: int() argument must be a string, a bytes-like object or a number, not 'tuple'. in python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM