title: Exec in Python 2.7.6
body: <p>I'm learning the basics of <strong>eval</strong>, <strong>exec</strong>, and <strong>compile</strong> on 2.7.6.</p>
  
  <p>I have hit a roadblock on <strong>exec</strong>, as I get an error when running this:</p>
  
  <pre><code>exec 'print 5'
  </code></pre>
  
  <p>Error:</p>
  
  <blockquote>
    <p>SyntaxError: unqualified exec is not allowed in function 'main' it
    contains a nested function with free variables (EvalExecCompile.py,
    line 61)</p>
  </blockquote>
  
  <p>I have found that <strong>exec</strong> is an expression in 2.7.6 while a function in 3.x. Problem is, I cannot find a working example to learn from for <strong>exec</strong> in 2.7.6.</p>
  
  <p>I am aware of all the dangers of using <strong>exec</strong>, etc., but just want to learn how to use them encase I ever need them.</p>
  
  <p>Could someone please help? Maybe provide a working example that I can dissect?</p>
  
  <p>Thank you.</p>
  
  <p>The goal of my question is to learn how to use <strong>exec</strong> in 2.7.6 properly.</p>