2024-04-24 14:51:34 发布
网友
所以我有下面的代码。基本上,它应该读入testcase.txt文件然后把它们打印出来,但是当我运行程序的时候它是空白的。有什么解决办法吗?你知道吗
testFile = 'testcase.txt' file = open(testFile, 'r') index = 0 for line in file: test_list.insert(index,line) index += 1 file.close()
您可能想更多地阅读有关pythonfile objects方法的文档,但这里:
filecontents = open('testcase.txt').readlines() #readlines automatically splits the file up by linebreaks for index,line in enumerate(filecontents): print(index,line)
您可能想更多地阅读有关pythonfile objects方法的文档,但这里:
相关问题 更多 >
编程相关推荐