I
iMath
redirect standard output problem
why the result only print A but leave out 888 ?
import sys
class RedirectStdoutTo:
def __init__(self, out_new):
self.out_new = out_new
def __enter__(self):
sys.stdout = self.out_new
def __exit__(self, *args):
sys.stdout = sys.__stdout__
print('A')
with open('out.log', mode='w', encoding='utf-8') as a_file, RedirectStdoutTo(a_file):
print('B')
print('C')
print(888)
why the result only print A but leave out 888 ?
import sys
class RedirectStdoutTo:
def __init__(self, out_new):
self.out_new = out_new
def __enter__(self):
sys.stdout = self.out_new
def __exit__(self, *args):
sys.stdout = sys.__stdout__
print('A')
with open('out.log', mode='w', encoding='utf-8') as a_file, RedirectStdoutTo(a_file):
print('B')
print('C')
print(888)