Monthly Archives: September 2009

Python eval

Generally, just use ‘exec’ statement instead of the ‘eval’ function

v = 1
exec 'v = 2'
print v

Python eval is a function meaning it doesn’t allow setting of variables. Usage is:
x = 1
print eval(‘x+1’)