(Please don't top-post. Put your remarks AFTER the part you're quoting from the previous message)

On 09/29/2011 10:55 AM, lina wrote:
import os.path

tokens=['E']
result=[]

for fileName in os.listdir("."):
     if os.path.isfile(fileName) and os.path.splitext(fileName)=="xpm":
         filedata = open(fileName)
         text=filedata.readlines()
         for line in text:


How can I read from line 24 and do further looking for "E".

Thanks,



As I said in my earlier message, this was untested. It gave you the building blocks, but was not correct.

In particular, that if-test will always fail, so you're not seeing any files.

import os.path

tokens=['E']
result=[]

for fileName in os.listdir("."):

    if os.path.isfile(fileName) and os.path.splitext(fileName)[1]==".xpm":
        filedata = open(fileName)
        text=filedata.readlines()
        for line in text:
            print line


Once you've tested that, then you're ready to just look at line 24.

text is a list, so you can refer to line 24 as text[24]

Or you can get lines 24-28, with text[24, 29] (look up slices in the Python doc)

==
DaveA


_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to