我试图编写一些代码,它将打开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