Skip to content

Instantly share code, notes, and snippets.

@msoedov
Created June 13, 2018 16:20
Show Gist options
  • Save msoedov/325a23309424fb45419908b4e8c7bf62 to your computer and use it in GitHub Desktop.
Save msoedov/325a23309424fb45419908b4e8c7bf62 to your computer and use it in GitHub Desktop.
def wrapper3():
v = dict(counter=0)
def incr():
v['counter'] += 1
return v['counter']
return incr
fn = wrapper3()
print(fn())
# >> 1
def wrapper4():
class Vars:
counter = 0
def incr():
Vars.counter += 1
return Vars.counter
return incr
fn = wrapper4()
print(fn())
# >> 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment