EOFError with fileinput

Alex van der Spek zdoor at xs4all.nl
Mon Aug 16 13:27:32 EDT 2010


Here is an excerpt. It works because the end condition is a fixed number 
(ln==10255), the approximate number of data lines in a file. If I replace 
that condition by EOFError, the program does not do the intended work. It 
appears as if EOFError is always true in this case.

+++++++++++++++++++++++++++++++++++++++++++

for line in fileinput.input(logs):
            if line.split()[0]=='DataID':
                datsec=True
                ln=0
            if datsec:
                lines[fn].append(line.split())
                ln+=1
                if ln==10255:
                    datsec=False
                    fileinput.nextfile()
                    fn+=1
                    print fileinput.filename().rsplit('\\',1)[1]
        fileinput.close()

+++++++++++++++++++++++++++++++++++++++++++

Regards,
Alex van der Spek


"Alex van der Spek" <zdoor at xs4all.nl> wrote in message 
news:4c696751$0$22940$e4fe514c at news.xs4all.nl...
> Using the fileinput module to process lists of files:
>
>>>>for line in fileinput.input(logs):
>
> Unfortunately, EOFError does not seem to indicate the end-of-file 
> condition correctly when using fileinput.
>
> How would you find the EOF file for all the files in the file list 'logs'?
>
> Thank you,
> Alex van der Spek 




More information about the Python-list mailing list