【发布时间】:2018-02-02 11:11:49
【问题描述】:
所以我试图添加存储在文件中的变量中存储的数字。
if rw == "s":
fo = open("foo.txt", "w")
while int(count) != 0:
x = input("Input a number for storage ")
count = int(count) - 1
test.append(int(x))
print("")
fo.write("%s" % test)
fo.close()
fo = open("foo.txt", "r")
add = int(fo.readlines(1)) + int(fo.readlines(2))
我不太明白最后一部分是如何工作的。我得到的错误如下:
TypeError: int() argument must be a string, a bytes-like object or a number, not 'list'
文件的内容如下所示:
[6, 7, 8, 9, 5, 4, 3]
任何帮助将不胜感激
【问题讨论】:
标签: arrays python-3.x file