我想編寫一個程序,打印出一個值超過另一個值的特定行/行線。例如,這是文本文件中的一小部分:如何根據條件(大於或小於)打印出文本文件中的特定行/行
01,test1,202,290,A,290
02,test2,303,730,A,0
03,test3,404,180,N,180
,我想代碼將選擇具有「A」在他們的所有行,但還可以選擇線,其中第4列的程序(290對於第一線)大於在第一行的第6列(290),然後打印them.So程序應該只打印在上面蟒蛇在文本文件中這一行:
02,test2,303,730,A,0
盡我所能do只是使用以下內容打印所有具有「A」的行:
F = open("TEST.txt").read()
for line in F.split():
if 'A' in line:
Column=line.split(',')
但是,這隻會選擇'A'在他們的行,當我試圖根據第4列是否大於第6列進行過濾時,我得到各種錯誤。有人可以幫我解決這個問題嗎?
謝謝!這個解決方案很好。 –
@ J.p然後你應該接受答案。 – AlokThakur