【发布时间】:2020-05-14 18:49:07
【问题描述】:
好的,这是我的代码,我想从文件中读取,然后将文件中的数字附加到列表中,然后附加一些其他数字,然后打印列表中最大的数字。这是代码
f = open("snake_settings\hs.txt", "r+") #In the file, there is number "7"
scores_list = [f.read()]
scores_list.append(4) #Random number just to test
print(max(scores_list)) #I want to print the biggest number in a list
这是错误
File "test.py", line 5, in <module>
print(max(scores_list))
TypeError: '>' not supported between instances of 'int' and 'str'
谢谢!
【问题讨论】:
-
你能发布一个这个测试文件的例子吗?它的格式是什么? ascii 中的数字列表,每行一个?