-6
所以我下面有這個代碼。基本上,它應該讀取testcase.txt中的行並將它們打印出來,但是當我運行該程序時它會變成空白。任何解決方案?有人可以解釋爲什麼Python不讀這個文件嗎?
testFile = 'testcase.txt'
file = open(testFile, 'r')
index = 0
for line in file:
test_list.insert(index,line)
index += 1
file.close()
此代碼是否運行?你有沒有實例化'''test_list'''? – wnnmaw 2014-10-07 13:44:24
我在代碼中看不到打印語句,所以不確定爲什麼你期望打印任何東西? – 2014-10-07 13:44:28
不是你的問題,但使用'enumerate()'而不是手動計數索引。 – geoffspear 2014-10-07 13:46:27