<br><br><div class="gmail_quote">On Thu, Sep 29, 2011 at 11:28 PM, Dave Angel <span dir="ltr">&lt;<a href="mailto:d@davea.name">d@davea.name</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
(Please don&#39;t top-post.  Put your remarks AFTER the part you&#39;re quoting from the previous message)<div class="im"><br>
<br>
On 09/29/2011 10:55 AM, lina wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
import os.path<br>
<br>
tokens=[&#39;E&#39;]<br>
result=[]<br>
<br>
for fileName in os.listdir(&quot;.&quot;):<br>
     if os.path.isfile(fileName) and os.path.splitext(fileName)==&quot;<u></u>xpm&quot;:<br>
         filedata = open(fileName)<br>
         text=filedata.readlines()<br>
         for line in text:<br>
<br>
<br>
How can I read from line 24 and do further looking for &quot;E&quot;.<br>
<br>
Thanks,<br>
<br>
<br>
</blockquote>
<br></div>
As I said in my earlier message, this was untested.  It gave you the building blocks, but was not correct.<br>
<br>
In particular, that if-test will always fail, so you&#39;re not seeing any files.<div class="im"><br>
<br>
import os.path<br>
<br>
tokens=[&#39;E&#39;]<br>
result=[]<br>
<br>
for fileName in os.listdir(&quot;.&quot;):<br>
<br></div>
    if os.path.isfile(fileName) and os.path.splitext(fileName)[1]=<u></u>=&quot;.xpm&quot;:<div class="im"><br>
        filedata = open(fileName)<br>
        text=filedata.readlines()<br>
        for line in text:<br></div>
            print line<br>
<br>
<br>
Once you&#39;ve tested that, then you&#39;re ready to just look at line 24.<br>
<br>
text is a list, so you can refer to line 24 as text[24]<br>
<br>
Or you can get lines 24-28, with  text[24, 29]   (look up slices in the Python doc)<br>
<br>
==<br>
DaveA<br>
<br>
<br>
</blockquote></div>Thanks for former help, <br><br>but I wonder how to output (write) the final result in each respectively fileName with just different extension, such as original a.xpm write to a.txt<br><br>Thanks,<br>
<br>#!/bin/python<br><br>import os.path<br><br>tokens=[&#39;E&#39;]<br>result=[]<br><br>for fileName in os.listdir(&quot;.&quot;):<br>    if os.path.isfile(fileName) and os.path.splitext(fileName)[1]==&quot;.xpm&quot;:<br>
        filedata = open(fileName)<br>        text=filedata.readlines()<br>        for line in text[23:len(text)-1]:<br>            result.append({t:line.count(t) for t in tokens})
<br>        for index,r in enumerate(result):
<br>            fileName.txt.write(index,&quot;-----&quot;,r)<br>???<br clear="all"><br>-- <br>Best Regards,<br><br>lina<br><br><br>