I am trying to follow a book step-by-step but I am either getting nothing back or getting errors.
Can anyone tell me what's going on?
import sys
class RedirectStdoutTo:
def _init_(self, out_new):
self.out_new=out_new
def _enter_(self):
self.out_old= sys.stdout
sys.stdout = self.out_new
def _exit_(self, *args):
sys.stdout = self.out_old
print('A')
with open('out.log', mode='w', encoding='utf-8') as a_file, RedirectStdoutTo(a_file):
print('B')
print('C')
And when I run in Python, I write python log.py
It returns an error saying:
File "<stdin>", line 1
python ilog.py
^
SyntaxError: invalid syntax