exec within function

Terry Reedy tjreedy at udel.edu
Wed Feb 3 14:59:17 EST 2010


On 2/3/2010 3:30 AM, Simon zack wrote:
> hi,
> I'm not sure how I can use exec within a function correctly
> here is the code i'm using:
>
> def a():
>      exec('b=1')
>      print(b)
>
> a()
>
> this will raise an error, but I would like to see it outputting 1

Always **copy and paste** **complete error tracebacks** when asking a 
question like this. (The only exception would be if it is v e r y long, 
as with hitting the recursion depth limit of 1000.)




More information about the Python-list mailing list