I'm learning the basics of eval, exec, and compile on 2.7.6.
I have hit a roadblock on exec, as I get an error when running this:
exec 'print 5'
Error:
SyntaxError: unqualified exec is not allowed in function 'main' it contains a nested function with free variables (EvalExecCompile.py, line 61)
I have found that exec 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 exec in 2.7.6.
I am aware of all the dangers of using exec, etc., but just want to learn how to use them encase I ever need them.
Could someone please help? Maybe provide a working example that I can dissect?
Thank you.
The goal of my question is to learn how to use exec in 2.7.6 properly.