[issue12020] Attribute error with flush on stdout,stderr

James Hutchison report at bugs.python.org
Fri May 6 20:28:06 CEST 2011


James Hutchison <jamesghutchison at gmail.com> added the comment:

You are right, when I add:

    def flush(self):
        pass;

the error goes away.

When I have this:

    def flush():
        pass;

I get:

Exception TypeError: 'flush() takes no arguments (1 given)' in <__main__.FlushFile object at 0x00C2AB70> ignored

This leads me to believe that sys.stdout.flush() is being called on program close

So this would be the correct implementation of my flushfile override:

class FlushFile(object):
    #"""Write-only flushing wrapper for file-type objects."""
    def __init__(self, f):
        self.f = f;
        self.flush = f.flush;
        try:
            self.encoding = f.encoding;
        except:
            pass;
    def write(self, x):
        self.f.write(x)
        self.f.flush()

----------

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


More information about the Python-bugs-list mailing list