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. Advertisements

  2. 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)

    --
     
    Dennis Lee Bieber, Jun 10, 2005
    #2
    1. Advertisements

  3. David Bear

    wittempj Guest

    wittempj, Jun 10, 2005
    #3
    1. Advertisements

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.