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

EOFError not getting raised

P: n/a
I have been trying to do something like this:

f = open('someDocs.str', 'r')
try:
while True:
ln = f.readline()
except EOFError:
print 'reached eof'
f.close()
sys.exit(1)
However, EOFError is never raised. What am I missing?
Jul 19 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
On Fri, 10 Jun 2005 06:49:51 +0000 (UTC), David Bear
<Da********@asu.edu> declaimed the following in comp.lang.python:
However, EOFError is never raised. What am I missing?
The Python Library Reference, perhaps?

-=-=-=-=-=-=-=- PLR
readline( [size])
Read one entire line from the file. A trailing newline character is kept
in the string2.11 (but may be absent when a file ends with an incomplete
line). If the size argument is present and non-negative, it is a maximum
byte count (including the trailing newline) and an incomplete line may
be returned. An empty string is returned only when EOF is encountered
immediately. Note: Unlike stdio's fgets(), the returned string contains
null characters ('\0') if they occurred in the input.
-=-=-=-=-=-=-=-

.readline() does NOT raise EOF.

f = open('someDocs.str', 'r')
while True:
ln = f.readline()
if not ln: break
print 'reached eof'
f.close()
sys.exit(1)

-- ================================================== ============ <
wl*****@ix.netcom.com | Wulfraed Dennis Lee Bieber KD6MOG <
wu******@dm.net | Bestiaria Support Staff <
================================================== ============ <
Home Page: <http://www.dm.net/~wulfraed/> <
Overflow Page: <http://wlfraed.home.netcom.com/> <

Jul 19 '05 #2

P: n/a
See http://docs.python.org/lib/module-exceptions.html: EOFError gets
raised when input() or raw_input() hit an EOF condition without reading
data.

Jul 19 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.