[issue4362] FileIO object in io module
Amaury Forgeot d'Arc
report at bugs.python.org
Thu Nov 20 16:31:07 CET 2008
Amaury Forgeot d'Arc <amauryfa at gmail.com> added the comment:
The attached patch is an attempt to set mode and name attributes to all
three objects in the IO stack.
>>> f = open("foo", "U+")
>>> f.buffer.name, f.buffer.mode
See also the unit tests.
There is a little inconsistency that I don't know how to resolve: with
my patch, the mode does not round-trip: open(name, mode).mode is not
always equal to mode:
>>> f = open("foo", "rb")
>>> f.name, f.mode
The 'b' was removed because f is already a binary file returning bytes.
But it seems better than attaching the initial mode to the FileIO
>>> io.open("foo", "Ub+", buffering=0)
>>> io.open("foo", "Ub+", buffering=0).mode
Which is even more surprising IMO.
keywords: +needs review, patch
Added file: http://bugs.python.org/file12072/fileio_attributes.patch
Python tracker <report at bugs.python.org>
More information about the Python-bugs-list