In a text file: how do I tell the EOF, from a blank line?
Steve Holden
steve at holdenweb.com
Wed May 16 22:31:00 EDT 2007
walterbyrd wrote:
> 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 ----------------
More information about the Python-list
mailing list