Hi all. I thought I had a pretty good grasp of Python's scoping rules, but today I noticed something that I don't understand. Can anyone explain to me why this happens?

>>> x = 'global'
>>> def f1():
    x = 'local'
    class C:
        y = x
    return C.y

>>> def f2():
    x = 'local'
    class C:
        x = x
    return C.x

>>> f1()
'local'
>>> f2()
'global'
--
https://mail.python.org/mailman/listinfo/python-list

Reply via email to