Mailing List Archive

Why is no exception raised for file.read() when file is only writeable?
I've been helping someone learn the language and he was having trouble
understanding why this didn't work:

test=open('testfile','w')
testread=test.readline()

I explained to him the problem, but I was wondering why Python doesn't raise
an exception when you do this. He probably wouldn't have had to ask me
anything if Python printed something like this:

IOError: [Errno X] You can't read from a file only open for writing.
Why is no exception raised for file.read() when file is only writeable? [ In reply to ]
From: Peter Haight <peterh@sapros.com>


I've been helping someone learn the language and he was having trouble
understanding why this didn't work:

test=open('testfile','w')
testread=test.readline()

I explained to him the problem, but I was wondering why Python doesn't raise
an exception when you do this. He probably wouldn't have had to ask me
anything if Python printed something like this:

IOError: [Errno X] You can't read from a file only open for writing.