As I am studying decorators, I noticed something strange :
def f():
... msg='aa'
... def a():
... print msg
... msg='bb'
... def b():
... print msg
... return a,b
...
>>> a,b = f()
>>> a()
bb
>>> b()
bb
>>>
Why a() returns ‘bb’ and not ‘aa’ ??
Because
aandbhave the same outer scope, in whichmsgis bound to'bb'. Put them in separate functions if you want them to have separate scopes.