[email protected] wrote:
... Removing the comment character to increase the stream
reference count fixes the program, at the expense of
an extra TextIOWrapper object.
But you do create that extra TextIOWrapper, so there should
be no crying about its existence. If you rely on the data structure
of another object, it is a good idea to hold onto that object, rather
than simply hold onto a field or two of its class.
So, at the least, you need these changes:
...
class file(io.TextIOWrapper):
...
def __init__(self, buffered_reader): # was ..., stream)
#self.stream = stream
super().__init__(buffered_reader) # was ...(stream.buffer)
...
print(file(open('p.py', 'rb')).read()) # was ...('p.py')...
But, I'd say the right was to write this last is:
with file(open('p.py', 'rb')) as src:
print(src.read())
--
http://mail.python.org/mailman/listinfo/python-list