for 實現:
import os;
# python 逐行讀取文本
for line in open( "c:\\testLineCount.txt", encoding = "utf-8" ): #
print( line );
#
while 實現:
path = "C:\\testLineCount.txt"
file1 = open( path, "r", encoding = "utf-8" )
while True: #
mystr = file1.readline() #表示一次讀取一行
# 讀到數據最後跳出,結束循環。數據的最後也就是讀不到數據了,mystr 爲空的時候
if mystr == '': # 或 if not mystr:
break;
print( mystr )
#
file1.close();