<br><br><div class="gmail_quote">On Thu, Sep 29, 2011 at 11:28 PM, Dave Angel <span dir="ltr"><<a href="mailto:d@davea.name">d@davea.name</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
(Please don't top-post. Put your remarks AFTER the part you'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=['E']<br>
result=[]<br>
<br>
for fileName in os.listdir("."):<br>
if os.path.isfile(fileName) and os.path.splitext(fileName)=="<u></u>xpm":<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 "E".<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're not seeing any files.<div class="im"><br>
<br>
import os.path<br>
<br>
tokens=['E']<br>
result=[]<br>
<br>
for fileName in os.listdir("."):<br>
<br></div>
if os.path.isfile(fileName) and os.path.splitext(fileName)[1]=<u></u>=".xpm":<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've tested that, then you'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=['E']<br>result=[]<br><br>for fileName in os.listdir("."):<br> if os.path.isfile(fileName) and os.path.splitext(fileName)[1]==".xpm":<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,"-----",r)<br>???<br clear="all"><br>-- <br>Best Regards,<br><br>lina<br><br><br>