exec within function
Gerald Britton
gerald.britton at gmail.com
Wed Feb 3 15:29:15 EST 2010
I get no error:
>>> def a():
... exec('b=1')
... print(b)
...
>>> a()
1
>>>
On Wed, Feb 3, 2010 at 2:59 PM, Terry Reedy <tjreedy at udel.edu> wrote:
> 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.)
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
--
Gerald Britton
More information about the Python-list
mailing list