Code: Select all
def func():
func.variable = "John"
func()
print(func.variable)
There. Accessing a variable from a function
But how do you do that with a generator?
Code: Select all
def func():
func.variable = "John"
func()
print(func.variable)
Code: Select all
t = 0
u = []
def h ():
while True:
t = t + 1
u.append(t)
yield u
h ()
Code: Select all
z = any(u)