python
# python取txt文件的有标志的下一行提取出来 import time import re try: f1 = open(r'E:\MY\work\zhuoyue\er\Error\AppLog_20180811-O_WebSocket.txt', 'rb') f2 = open(r'E:\MY\work\zhuoyue\er\Error\AppLog_20180811-O_WebSocketTest.txt', 'ab') while True: line = f1.readline() buffy = "-------------------------" for line in f1: if buffy in str(line): # 你判定是否要提取字段的条件 MyLine = f1.readline() print(MyLine) #f2.write(MyLine) # 写入字段在新文件中 finally: f1.close() f2.close()