[New-bugs-announce] [issue8893] file.{read, readlines} behaviour on Solaris

Christophe Kalt report at bugs.python.org
Fri Jun 4 01:50:44 CEST 2010

New submission from Christophe Kalt <python at ote.taranis.org>:

The following snippet of code is a concise way to exhibit the problem:

import os

wr = open('/tmp/test', 'w')
rd = open('/tmp/test', 'r')
rdlns = open('/tmp/test', 'r')
# first, read til EOF is reached (which is right away)
assert len(rd.read()) == 0
assert len(rdlns.readlines()) == 0
# add data to the file
# try to read again
print 'read     : ', rd.read().split() # fails
print 'readlines: ', rdlns.readlines() # fails
print 'readline : ', rdlns.readline().strip() # succeeds
# cleanup

On Linux, here is the output:
$ python2.6 src/readlines.py
read     :  ['oink', 'oink']
readlines:  ['oink\n', 'oink\n']
readline :  

On Solaris, here is the output:
$ python src/readlines.py
read     :  []
readlines:  []
readline :  oink

The problems comes from the fact that once EOF is reached, nothing more will be read from the file on subsequent reads, as noted in the manual page (http://docs.sun.com/app/docs/doc/816-5168/getchar-3c?a=view):

"If the stream is at end-of-file, the end-of-file indicator for the stream is set and these functions return EOF. For standard-conforming (see standards(5)) applications, if the end-of-file indicator for the stream is set, these functions return EOF whether or not the stream is at end-of-file."

The attached diff fixes the problem.

assignee: theller
components: ctypes
files: fileobject.diff
keywords: patch
messages: 106999
nosy: kalt, theller
priority: normal
severity: normal
status: open
title: file.{read,readlines} behaviour on Solaris
type: behavior
versions: Python 2.6
Added file: http://bugs.python.org/file17542/fileobject.diff

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list