Python handles globals badly.

Chris Angelico rosuav at gmail.com
Fri Sep 11 11:15:14 EDT 2015


On Sat, Sep 12, 2015 at 1:03 AM, Ian Kelly <ian.g.kelly at gmail.com> wrote:
>> There's also a bunch of specialised and complicated rules for what happens
>> if you make a star import ("from module import *") inside a function, or
>> call eval or exec without specifying a namespace. Both of these things are
>> now illegal in Python 3.
>
> Huh?
>
>>>> exec("x = 42")
>>>> x
> 42
>>>> exec("x = 43", None, None)
>>>> x
> 43
>
> That's in Python 3.4.0. Maybe I don't understand what you mean by
> "without specifying a namespace".

*inside a function*

>>> def f():
...    exec("x = 42")
...    print(x)
...
>>> x = 231
>>> f()
231

ChrisA



More information about the Python-list mailing list