[Python-bugs-list] [ python-Bugs-420771 ] 'rw' option to open: is it a bug?

noreply@sourceforge.net noreply@sourceforge.net
Fri, 11 May 2001 13:03:31 -0700


Bugs item #420771, was updated on 2001-05-02 10:11
You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=420771&group_id=5470

Category: Python Library
Group: Feature Request
>Status: Closed
>Resolution: Wont Fix
Priority: 5
Submitted By: Nobody/Anonymous (nobody)
Assigned to: Nobody/Anonymous (nobody)
Summary: 'rw' option to open: is it a bug?

Initial Comment:
if you open a file with 'rw'

f = open('foo.bar','rw')
ie you will be able to read, but not write

Python 2.1 (#3, Apr 19 2001, 11:45:56) [C] on sunos5
Type "copyright", "credits" or "license" for more
information.
>>> f = open("foo.bar",'rw')
>>> f.read()
'HelloWorld\n'
>>> f.write("NotWhatIExpect")
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
IOError: [Errno 9] Bad file number
>>> 

However the rw does not seem to be a valid option, yet
no error is produced upon opening the file, rather
when the operation is attempted.

It seems that what is needed if you want
'rw' is 'r+'.

>>> f = open("foo.bar",'r+')
>>> f.read() 
'HelloWorld\n'
>>> f.write("ThisIsWhatIExpect")
>>> f.close()

Could therefore 'rw' signal an error? Or do the
same as 'r+'?

  

 

----------------------------------------------------------------------

>Comment By: Fred L. Drake, Jr. (fdrake)
Date: 2001-05-11 13:03

Message:
Logged In: YES 
user_id=3066

Tim's right.  There's no good reason to change this so long
as we rely on the platforms standard I/O libraries, so I'm
closing this as "Won't Fix".  It can be reasonably argued
that this is a bug, but in the platform libraries, not Python.

----------------------------------------------------------------------

Comment By: Tim Peters (tim_one)
Date: 2001-05-02 10:57

Message:
Logged In: YES 
user_id=31435

Python doesn't look at the mode argument:  it passes it on 
as-is to the platform C fopen() function.  This allows 
people to use whatever non-standard modes their platform 
supports.  An error is reported if and only if the platform 
fopen() sets errno across the call.

Mode "rw" isn't defined by C ("r+" and "w+" are), so 
whether a platform accepts it is up to the platform; and, 
if it does accept it, what it means is also up to the 
platform.  So that "rw" was accepted when you tried it 
means that sunos5's fopen() accepts an "rw" mode.  You'll 
have to consult Sun's docs for whether it's working as they 
intended it to work.

Could be useful if Python warned about non-standard modes.

----------------------------------------------------------------------

You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=420771&group_id=5470