1 2 3 4 5 6 7 8 9 10 11 12 13 14
def get_match(): cache=[1] def match(v): try: if cache: return cache except NameError: print 'NameError caught' cache = [v] return cache return match m = get_match() print m(2) print m(3)
1 2 3 4
NameError caught [2] NameError caught [3]