I always learn that the use of global variables is to be discouraged. Is this the only way to copy static variable behaviour in Python?
bumsfeld
Nearly a Posting Virtuoso
1,445 posts since Jul 2005
Reputation Points: 404
Solved Threads: 184
Bumsfeld you are right, avoid globals, they do lead to errors. Using a generator function avoids globals ...
def static_num2():
k = 0
while True:
k += 1
yield k
static = static_num2().next
for i in range(0,10) :
print static()
vegaseat
DaniWeb's Hypocrite
5,989 posts since Oct 2004
Reputation Points: 1,345
Solved Threads: 1,417
I knew there had to be a way to avoid these global variables, I am still learning a lot, generator functions are somewhat confusing right now!
bumsfeld
Nearly a Posting Virtuoso
1,445 posts since Jul 2005
Reputation Points: 404
Solved Threads: 184