所以我在下面有这个代码。基本上,它应该读取testcase.txt中的行并打印出来,但是当我运行程序时它会变成空白。任何解决方案吗?
testFile = 'testcase.txt'
file = open(testFile, 'r')
index = 0
for line in file:
test_list.insert(index,line)
index += 1
file.close()
答案 0 :(得分:1)
您可能希望更多地阅读有关python file objects'的文档。方法,但在这里:
filecontents = open('testcase.txt').readlines()
#readlines automatically splits the file up by linebreaks
for index,line in enumerate(filecontents):
print(index,line)