exec within function

Simon zack simonzack at gmail.com
Wed Feb 3 09:30:41 CET 2010


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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20100203/859b9624/attachment.html>


More information about the Python-list mailing list