[issue4829] confusing error for file("foo", "w++")

Ulrich Eckhardt report at bugs.python.org
Tue Jun 2 11:46:06 CEST 2009


Ulrich Eckhardt <eckhardt at satorlaser.com> added the comment:

Good catch, it just took me a while to actually figure out myself where
the bug is. Try the following instead:

  import io
  io.FileIO('foo.text', 'w++')

This will yield "ValueError: Must have exactly one of read/write/append
mode" with 2.6 on win32. I haven't tested on the latest 2.x or 3.x
branches, but looking at the 2.7 branch, I see the faulty code is still
there.

BTW:
Using io.open('foo.text', 'w++') yields "ValueError: invalid mode:
'w++'", I would have expected the same error as for io.FileIO() above.
Using open('foo.text', 'w++') works.
Using open('foo.text', 'ww++') yields "IOError: [Errno 22] invalid mode
('ww++') or filename: 'foo.text')".

In other words, Python 2.6 is behaving a bit inconsistent here. The
patch only fixes one of those issues, the others and the necessary unit
tests remain.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue4829>
_______________________________________


More information about the Python-bugs-list mailing list