I'm reading Wes McKinney's Python for Data Analysis and there's a section I don't quite understand. The code below is an example of a closure that works:
def make_watcher():
have_seen = {}
def has_been_seen(x):
if x in have_seen:
return True
else:
have_seen[x] = True
return False
return has_been_seen
Wes mentions that one technical limitation to keep in mind is that while you can mutate any internal state objects (like adding key-value pairs to a dict), you can't bind variables in the enclosing function scope. Can someone provide an example of what he means by the technical limitation? I'm not sure I can visualize an example.