Hi, folks.

I know that it is not possible to change local vars via `locals()` (except
in module-level).

```
import sys

def f1():
    x = 1
    d = locals()
    d['x'] = 2
    print(x)  #=> 1  (not changed)

f1()
```

But I found that it is possible in class definition.

```
import sys

class Foo:
    x = 1
    d = locals()
    d['x'] = 2
    print(x)  #=> 2  (changed!!!)
```

Can anyone explain about difference between above two?
Why it is possiable to change local var via `locals()` only in class
definition?
-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to