title: Why is my python file not running?
body: <p>I am trying to follow a book step-by-step but I am either getting nothing back or getting errors. </p>
  
  <p>Can anyone tell me what's going on?</p>
  
  <pre><code>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')
  </code></pre>
  
  <p>And when I run in Python, I write <code>python log.py</code></p>
  
  <p>It returns an error saying:</p>
  
  <pre><code>File "&lt;stdin&gt;", line 1
      python ilog.py
                ^
  SyntaxError: invalid syntax
  </code></pre>