Dan's idea doesn't quite work:
def __init__(self, f):
self.f = f
def write(self, x):
sys.stdout = flushfile(sys.stdout)
Traceback (most recent call last):
File "./passpersist.py", line 12, in <module>
ValueError: I/O operation on closed file
I believe the problem is that it inherits from the file class, which actually isn't necessary. According to the docs for sys.stdout:
stdout and stderr needn’t be built-in
file objects: any object is acceptable
as long as it has a write() method
that takes a string argument.
makes it work just fine.