<p>我有一个大约500MB的巨大文本文件,我需要打印与输入匹配的行,以及前3行和后3行</p>
<p>我的文本文件如下所示:</p>
<pre><code>...
...
...
benz is a nice car
...
...
...
its also said benz is a safe car
...
...
...
</code></pre>
<p>如果用户输入为'奔驰',那么它应该打印3行之前和之后的匹配,为每个单独的匹配</p>
<p>我的code:- 你知道吗</p>
<pre><code>users= raw_input('enter the word:')
with open('mytext.txt',rb) as f:
for line if f:
if users in line:
print line(i-3)
print line
print line(i+3)
</code></pre>
<p>但我没有定义错误</p>