python: what is `nonlocal` (intermediate) anthony explains #169

preview_player
Показать описание
today I talk about `nonlocal` and how you can use it to modify variables in closure. I also show a pattern which was used previous to this being a feature in python 3

==========

I won't ask for subscriptions / likes / comments in videos but it really helps the channel. If you have any suggestions or things you'd like to see please comment below!
Рекомендации по теме
Комментарии
Автор

there's a James Powell talk called "so you want to be a python expert" where he covers object-closure duality, and that's where I learned about nonlocal. Pretty cool talk, took me 3 years and 3 rewatches to really get all of it.

sadhlife
Автор

Nonlocal, notlocal, isnotlocal, foreign, someoneelses, cross-country, outlandish, alien, extraterestrial..

JakubYTb
Автор

This was new to me. I've been resorting to global, but this seems to be more explicit in what scope your accessing.

kristofferbakkejord
Автор

you sound like the guy from daily dose of internet

legend
Автор

what annoys me about javascript is that it is block scoped, so even stuff like if statements and for loops shadow the outer scope if you do declarations inside them, which leads to some pretty bad code choices on my part.

for eg, you cant do

if (x)
const y = foo(x)
else
const y = 42

y won't actually be defined in any useful scope

sadhlife