1

我有以下代码,我试图在作为第一个参数传递的给定输入文件中对“警告”“wcnss_proc\bt”进行 grep,但是 output.txt 仅用于“警告”......下面的代码有错吗?我想为输入文件中的所有行同时输入“警告”和“wcnss_proc\bt”

import sys

def filter_log(input_file, output_file, strs):
    with open(input_file, "r") as input, open(output_file, "w") as output:
        output.writelines(filter(lambda x: any([s in x for s in strs]), input.readlines()))

# here is just searched for "Warning", add other stuff

filter_log(sys.argv[1], "output.txt", ["Warning","wcnss_proc\bt"])
4

1 回答 1

2

\b是一个转义字符。你的意思是\\b

于 2013-09-25T21:16:39.020 回答