# -*- coding: utf-8 -*- """ Created on Thu Mar 11 22:25:32 2021 @author: jdwang """ # ch14_18.py #fn = 'ch14_15.txt' # 設定欲開啟的檔案 fn = 'D:\Python_jdwang\Temp\TDCS_M06A_20210224_180000.csv' cnt = 0 with open(fn) as file_Obj: # 用預設mode=r開啟檔案,傳回檔案物件file_Obj for line in file_Obj: # 逐行讀取檔案到變數line Items = line.split(',') #if (line.find('03F2100S') != -1): if (Items[2].find('03F2100S') != -1): print(str(cnt)+ "=>"+line) # 輸出變數line相當於輸出一行 cnt = cnt+1 print(cnt)