文本文件,我有這個文本文件:搜索詞Python中
MemTotal,5,2016-07-30 12:02:33,781
model name,3,2016-07-30 13:37:59,074
model,3,2016-07-30 15:39:59,075
我需要找到與模型線。
我的代碼:
term = "model"
file = open('file.txt')
for line in file:
line.strip().split('/n')
if term in line:
print line
file.close()
這是輸出:
model name,3,2016-07-30 13:37:59,074
model,3,2016-07-30 15:39:59,075
我只需要這一行作爲輸出:
model,3,2016-07-30 15:39:59,075
我怎樣才能做到這一點?
'項=「模式,」'反正這取決於它是否是一個一般的情況下,或特定的一個 – Samuel
'line.strip ().split('/ n')'什麼都不做。 「strip」和「split」不適用。 –