O'Reilly logo
  • Brandon Reeser thinks this is interesting:

The nonlocal statement makes it clear when data is being assigned out of a closure into another scope. It’s complementary to the global statement, which indicates that a variable’s assignment should go directly into the module scope.

However, much like the anti-pattern of global variables, I’d caution against using nonlocal for anything beyond simple functions. The side effects of nonlocal can be hard to follow. It’s especially hard to understand in long functions where the nonlocal statements and assignments to associated variables are far apart.

From

Cover of Effective Python: 59 Specific Ways to Write Better Python

Note

check this out for next week project