On Tue, Mar 22, 2016 at 11:57 PM, Steven D'Aprano wrote:
> Anyone have any idea what is going on here?
>
>
> def test():
> spam = 1
> exec("spam = 2; print('inside exec: %d' % spam)")
> print('outside exec: %d' % spam)
>
>
> In Python 2.7:
>
> py> test()
> inside exec: 2
> outside exec
Anyone have any idea what is going on here?
def test():
spam = 1
exec("spam = 2; print('inside exec: %d' % spam)")
print('outside exec: %d' % spam)
In Python 2.7:
py> test()
inside exec: 2
outside exec: 2
In Python 3.4:
outside exec: 1
py> test()
inside exec: 2
outside exec: 1