Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > EOFError not getting raised

Reply
Thread Tools

EOFError not getting raised

 
 
David Bear
Guest
Posts: n/a
 
      06-10-2005
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?
 
Reply With Quote
 
 
 
 
Dennis Lee Bieber
Guest
Posts: n/a
 
      06-10-2005
On Fri, 10 Jun 2005 06:49:51 +0000 (UTC), David Bear
<(E-Mail Removed)> 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)

--
> ================================================== ============ <
> http://www.velocityreviews.com/forums/(E-Mail Removed) | Wulfraed Dennis Lee Bieber KD6MOG <
> (E-Mail Removed) | Bestiaria Support Staff <
> ================================================== ============ <
> Home Page: <http://www.dm.net/~wulfraed/> <
> Overflow Page: <http://wlfraed.home.netcom.com/> <

 
Reply With Quote
 
 
 
 
wittempj@hotmail.com
Guest
Posts: n/a
 
      06-10-2005
See http://docs.python.org/lib/module-exceptions.html: EOFError gets
raised when input() or raw_input() hit an EOF condition without reading
data.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
EOFError with fileinput Alex van der Spek Python 5 08-17-2010 03:44 PM
EOFError: EOF when reading a line Mihir Patel Python 1 03-12-2010 01:22 AM
ftplib returns EOFError Jon Bowlas Python 0 05-19-2008 11:27 AM
Exception EOFError. Dr. Pastor Python 3 09-04-2006 07:35 AM
Mysterious EOFError Rex Eastbourne Python 3 04-09-2006 10:23 PM



Advertisments