Consider the programm:
x = 0
def f():
c = 2
def g():
c = 4
print(c)
print(c)
I want that the c
in g()
is the same as the c
in f()
.
Normally one would use the keyword global
within g()
, but this is not possible, since global
would refer to something outside f()
and not within f()
.
I imagine it this way: the program is the 'first universe'. A function is a new 'second universe' in that big first universe. A function within a function is a 'third universe' within the second universe. And so on. But using global refer immediately to the first universe, no matter in which universe I am. But I want a keyword that goes few universes back and not every universe.
Is this possible? Some kind of using a local variable as a global variable in the smaller scope?