By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,402 Members | 1,047 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,402 IT Pros & Developers. It's quick & easy.

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

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

May 17 '07 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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 ----------------

May 17 '07 #2

P: n/a
On 2007-05-17, walterbyrd <wa********@iname.comwrote:
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.
--
Grant Edwards grante Yow! Uh-oh!! I forgot
at to submit to COMPULSORY
visi.com URINALYSIS!
May 17 '07 #3

P: n/a
On May 16, 10:12 pm, Grant Edwards <gra...@visi.comwrote:
On 2007-05-17, walterbyrd <walterb...@iname.comwrote:
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.

May 17 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.