擅长:python、mysql、java
<p>对代码的一些注释:</p>
<p>现在,您已经将要查找的字符串和文件名硬编码为“string”和“tsvfile”。试试这个:</p>
<pre><code>subprocess.check_output(['grep', string, tsvfile])
</code></pre>
<p>接下来,如果使用<code>zgrep</code>,则不需要使用<code>gzip.open</code>打开文件。您可以对<code>tsv.gz</code>文件调用zgrep,它将负责打开它,而不需要您做任何额外的工作。所以试着打电话</p>
^{pr2}$
<p>请注意,<code>zgrep</code>也可以处理未压缩的<code>tsv</code>文件,因此不需要在grep和zgrep之间切换。在</p>