EOFError not getting raised

Discussion in 'Python' started by David Bear, Jun 10, 2005.

  1. David Bear

    David Bear Guest

    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?
    David Bear, Jun 10, 2005
    #1
    1. Advertising

  2. On Fri, 10 Jun 2005 06:49:51 +0000 (UTC), David Bear
    <> 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)

    --
    > ============================================================== <
    > | Wulfraed Dennis Lee Bieber KD6MOG <
    > | Bestiaria Support Staff <
    > ============================================================== <
    > Home Page: <http://www.dm.net/~wulfraed/> <
    > Overflow Page: <http://wlfraed.home.netcom.com/> <
    Dennis Lee Bieber, Jun 10, 2005
    #2
    1. Advertising

  3. David Bear

    Guest

    , Jun 10, 2005
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Rex Eastbourne

    Mysterious EOFError

    Rex Eastbourne, Apr 9, 2006, in forum: Python
    Replies:
    3
    Views:
    962
    Dennis Lee Bieber
    Apr 9, 2006
  2. Dr. Pastor

    Exception EOFError.

    Dr. Pastor, Sep 4, 2006, in forum: Python
    Replies:
    3
    Views:
    440
    Sybren Stuvel
    Sep 4, 2006
  3. Jon Bowlas

    ftplib returns EOFError

    Jon Bowlas, May 19, 2008, in forum: Python
    Replies:
    0
    Views:
    301
    Jon Bowlas
    May 19, 2008
  4. Mihir Patel

    EOFError: EOF when reading a line

    Mihir Patel, Mar 11, 2010, in forum: Python
    Replies:
    1
    Views:
    1,769
    Gabriel Genellina
    Mar 12, 2010
  5. Alex van der Spek

    EOFError with fileinput

    Alex van der Spek, Aug 16, 2010, in forum: Python
    Replies:
    5
    Views:
    538
    Alex van der Spek
    Aug 17, 2010
Loading...

Share This Page