Skip to content

Instantly share code, notes, and snippets.

@Fhernd
Created November 24, 2018 14:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Fhernd/2db6d836754d2251e4454dcc195b8e3b to your computer and use it in GitHub Desktop.
Save Fhernd/2db6d836754d2251e4454dcc195b8e3b to your computer and use it in GitHub Desktop.
Acceso a variables de un closure.
def fn():
n = 0
def fn_closure():
print('n = {}'.format(n))
def obtener_n():
return n
def establecer_n(valor):
nonlocal n
n = valor
fn_closure.obtener_n = obtener_n
fn_closure.establecer_n = establecer_n
return fn_closure
f = fn()
f()
f.establecer_n(10)
f()
n = f.obtener_n()
print(n)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment