我有一個文件,我正在搜索並將結果打印到文件中。我想知道是否可以修改下面的代碼來讀取多個搜索條件,即打印任何具有「test」或「hello」(用戶將指定)的行,但是Python會爲每個搜索項創建一個新的輸出文件?多個搜索條件和輸出文件
即Ofile1將舉行包括「測試」 Ofile2將舉行包括「你好」等
f = open('file3.txt') #input file
term = raw_input("What would you like to search for?") #takes an input to be searched
for line in f:
if term in line:
print (line) #print line of matched term
f.close() #close file
這是可以做到的所有行的所有行?
在詢問之前,您是否在尋找一些信息?這是非常簡單的問題。 –
不要吝嗇,但我不會問我是否找到它。 – here2learn