In a text file: how do I tell the EOF, from a blank line?

W

walterbyrd

How do I test for the end of a file, in such a why that python can
tell the EOF from a blank line?
 
S

Steve Holden

walterbyrd said:
How do I test for the end of a file, in such a why that python can
tell the EOF from a blank line?
Only when the EOF is reached will you read an entirely empty line. Real
empty lines read as a newline terminator.

However, there are any better ways to process the lines of a file than
reading it line by line. For example you can iterate over the lines with
something like

f = open("myfile.txt", 'r')
for line in f:
... do something with line ...

regards
Steve
--
Steve Holden +1 571 484 6266 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://del.icio.us/steve.holden
------------------ Asciimercial ---------------------
Get on the web: Blog, lens and tag your way to fame!!
holdenweb.blogspot.com squidoo.com/pythonology
tagged items: del.icio.us/steve.holden/python
All these services currently offer free registration!
-------------- Thank You for Reading ----------------
 
G

Grant Edwards

How do I test for the end of a file, in such a why that python can
tell the EOF from a blank line?

This has already been explained to you by at least 5 different
people -- complete with examples.
 
W

walterbyrd

This has already been explained to you by at least 5 different
people -- complete with examples.


Sorry about dual posting. I am using google groups. Usually, after I
submit a message, I can find that message after a few minutes. This
time, I could not find the messages that I posted after waiting for
hours. I figured something must have gone wrong, so I re-posted.
 

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,743
Messages
2,569,478
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top