斯蒂芬·劳赫给出的答案是很酷,但我认为你是python的新手,所以这里是一个基本功能。
考虑,“START”必须始终在消息的开始,而不是之间像,
[739:247021] PHYThrad: START DSPMsgQ Received: msg type is[130] and SFNSF [14997] [SFN:937 SF:5] # START at second index after split.
如果我们考虑以上使用的情况下,这里是可以打印本"START"
线功能在日志消息开始的文件中。
def getStart(filename):
with open(filename, "r") as reader:
for lines in reader.readlines(): # get list of lines
start = lines.split(' ')[1] # Split with space, and check the word is "START"
if start =='START':
print lines
getStart("a.txt") # considering your filename is a.txt.
输出:
[739:246050] START of MACThread:receved msg type[47]
[739:247059] START of MACThread:receved msg type[47]
为什么你使用'__contains__',而不是'in'? –