在shell中,cat filename | grep -i error会返回包含字符串' error'的文件中的内容。
Python的等价物是什么?
答案 0 :(得分:2)
打开文件,遍历所有行并仅在行包含List<Car> carStatus =
(from car in person
where car.ModelName != "Corolla"
where car.Color == "blue"
select car.ModelName).ToList();
时打印行。
error
用于不区分大小写的匹配,
with open(file) as f:
for line in f:
if 'error' in line:
print(line)