title: Python Trace Tables and ver 2 to ver 3 issue
body: <p>I found this code for printing a program trace and it works fine in Python2.</p>
  
  <p>However, in Python 3 there are issues. I addressed the first one by replacing <code>execfile(file_name)</code> with <code>exec(open(filename).read())</code>, but now there is still an error of <code>KeyError: 'do_setlocale'</code></p>
  
  <p>I'm out of my depth here - I just want an easy way to trace variables in programs line by line - I like the way this program works and it would be great to get it working with Python 3. I even tried an online conversion program but got the same <code>KeyError: 'do_setlocale'</code></p>
  
  <p>Can anyone please help me to get it working?</p>
  
  <pre><code>import sys
  
  if len(sys.argv) &lt; 2:
          print __doc__
          exit()
  else:
          file_name = sys.argv[1]
  
  past_locals = {}
  variable_list = []
  table_content = ""
  
  ignored_variables = set([
          'file_name',
          'trace',
          'sys',
          'past_locals',
          'variable_list',
          'table_content',
          'getattr',
          'name',
          'self',
          'object',
          'consumed',
          'data',
          'ignored_variables'])
  
  def trace(frame, event, arg_unused):
          global past_locals, variable_list, table_content, ignored_variables
          relevant_locals = {}
          all_locals = frame.f_locals.copy()
          for k,v in all_locals.items():
                   if not k.startswith("__") and k not in ignored_variables:
                              relevant_locals[k] = v
          if len(relevant_locals) &gt; 0 and past_locals != relevant_locals:
                   for i in relevant_locals:
                              if i not in past_locals:
                                       variable_list.append(i)
                   table_content += str(frame.f_lineno) + " || "
                   for variable in variable_list:
                              table_content += str(relevant_locals[variable]) + " | "
                   table_content = table_content[:-2]
                   table_content += '\n'
                   past_locals = relevant_locals
          return trace
  
  sys.settrace(trace)
  
  execfile(file_name)
  
  table_header = "L || "
  for variable in variable_list:
          table_header += variable + ' | '
  table_header = table_header[:-2]
  print table_header
  print table_content
  
  # python traceTable.py problem1.py
  
  # problem1.py
  a = 1
  b = 2
  
  a = a + b
  </code></pre>