sys.stndout syntax
Barry A. Warsaw
bwarsaw at beopen.com
Fri Aug 18 18:06:33 EDT 2000
>>>>> "BP" == Bjorn Pettersen <bjorn at roguewave.com> writes:
BP> Both at the same time:
BP> class Echo:
| def __init__(self, f):
| self.f = open(f, 'w')
| def write(self, txt):
| self.f.write(txt)
| sys.__stdout__.write(txt)
| sys.stdout = Echo('file.txt')
| print 'on screen, and on file...'
| sys.stdout = sys.__stdout__
| closing-the-file-left-as-an-excercise'ly y'rs
so-is-repairing-sys.stdout-if-you-were-to-print-an-object-with-a-
str()-method-that-raised-an-exception!-ly y'rs,
-Barry
More information about the Python-list
mailing list