Graceful detection of EOF

F

Follower

Egbert Bouwman said:
Of course it is not difficult to test if you are reading the first line
or another one, but it hurts my feelings to do a test which by definition
succeeds at the first record, and never afterwards.
Any suggestions ?
An alternative approach (which I'm sure will offend just as many
sensibilities) is to use a function that replaces itself.

------ Pseudo-code ------


def process_firstline(...):

# ...do something here...
global processline
processline = process_otherlines


def process_otherlines(...):

# ...do something here...


processline = process_firstline

for line in file:
result = processline(line)

----------------------------

If you read more than one file you'll need to reset processline at the
beginning of each file.

I never said this was a *good* way, just one way. :)

--Phil.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,077
Latest member
SangMoor21

Latest Threads

Top