我要尋找一個在Python中的文件中的一些話。找到每個單詞後,我需要從文件中讀取下兩個單詞。我尋找了一些解決方案,但是我找不到接下來的單詞。閱讀文件的下一個單詞在python
# offsetFile - file pointer
# searchTerms - list of words
for line in offsetFile:
for word in searchTerms:
if word in line:
# here get the next two terms after the word
謝謝您的時間。
更新:只有首先出場的是必要的。實際上,在這種情況下,這個詞只有一個可能。
文件:
accept 42 2820 access 183 3145 accid 1 4589 algebra 153 16272 algem 4 17439 algol 202 6530
字: '訪問', '代數']
搜索文件時,我遇到 '訪問' 和 '代數',我需要的183 3145的價值觀和153 16272。
你應該張貼的文件的外觀LIK爲例即 – Akavall 2012-04-22 01:33:34
爲你最後的評論,你的意思是你在行中找到的單詞後面的兩個單詞嗎?你能提供一些樣本輸入/輸出嗎? – Levon 2012-04-22 01:35:02