<p>我的代码</p>
<pre><code>def yieldlines(thefile, whatlines):
return (x for i, x in enumerate(thefile) if i in whatlines)
file1=open('/home/milenko/EDIs/site1/newst2.txt','r')
whatlines1 = [line.strip() for line in open('m1.dat', 'r')]
x1=yieldlines(file1, whatlines1)
print x1
</code></pre>
<p>我得到了</p>
<pre><code><generator object <genexpr> at 0x7fa3cd3d59b0>
</code></pre>
<p>我应该把列表放在哪里,或者我需要重写代码?</p>
<p>我希望我的程序能够打开文件并读取内容,以便对m1.dat中写入的特定行进行读取
<a href="https://stackoverflow.com/questions/2081836/reading-specific-lines-only-python">Reading specific lines only (Python)</a></p>