Looking at learn Python recently, see the effect of using function properties to accomplish nonlocal.
def test (start):
def Nest (label):
print (label,nest.state)
nest.state+=1
Nest.state=start
Return Nest
Personally think this is typographical error. Should be as follows:
def test (start):
def Nest (label):
print (label,nest.state)
nest.state+=1
Nest.state=start
Return Nest
But that's not what this article wants to record. Actually want to write down is a point:
def test ():
... content ...
for function test (), test.value= ... is feasible, but test (). Value= ... is not feasible.
A=test
B=test
A.value=1
b.value=1!
That is, the attribute is shared in the local space, and if you want to implement different calls to get different property values, you need to initialize them by nesting the first function.
But one question has not been tested: After modifying the properties of a function, the property is still available the next time the function is used independently. Although in and not actually does not affect the function use, but this should design the function the mechanism.