我有一个文本文件,我想导入为在本作-while循环使用的列表:Python的导入文本文件列表重述
text_file = open("/Users/abc/test.txt", "r")
list1 = text_file.readlines
list2=[]
for item in list1:
number=0
while number < 5:
list2.append(str(item)+str(number))
number = number + 1
print list2
但是当我运行它,它输出:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'builtin_function_or_method' object is not iterable
我该怎么办?
它应该是'text_file.readlines()''不text_file.readlines' – sshashank124