我試圖編寫一些代碼,它將打開List1.txt
並複製內容,直到看到字符串'John smith'
到List2.txt
。從文件中複製,直到找到某個標記字符串
這是我到目前爲止有:
F=open('C:\T\list.txt','r').readlines()
B=open('C:\T\list2.txt','w')
BB=open('C:\T\list2.txt','r').readlines()
while BB.readlines() == 'John smith':
B.writelines(F)
這裏是什麼List1.txt
可以包含一個例子:
Natly molar
Jone rock
marin seena
shan lra
John smith
Barry Bloe
Sara bloe`
但是,它似乎並不奏效。我究竟做錯了什麼?
對於初學者你的路是錯誤的。更改\ \ \或/ – bernie 2010-10-21 15:49:27
您正在打開list2.txt進行寫入並立即打開它以供讀取?然後你正在閱讀它?這應該如何工作?我期望寫調用截斷文件,以便讀取循環沒有任何內容。 – hughdbrown 2010-10-21 15:53:24