Re: exec within function

2010-02-03 Thread Peter Otten
Gerald Britton wrote: > On Wed, Feb 3, 2010 at 2:59 PM, Terry Reedy 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 w

Re: exec within function

2010-02-03 Thread Gerald Britton
I get no error: >>> def a(): ... exec('b=1') ... print(b) ... >>> a() 1 >>> On Wed, Feb 3, 2010 at 2:59 PM, Terry Reedy 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(): >>    

Re: exec within function

2010-02-03 Thread Terry Reedy
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 tracebac

exec within function

2010-02-03 Thread Simon zack
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 thanks smk -- http://mail.python.org/mailman/listinfo/python-list