Mar-10-2019, 05:50 PM
Hi all,
Does anyone know if Python supports non-volatile local variables
?
I was wondering if there was a way to keep the variable alive. I know that I can simply declare it as global, but then every function could read it. I was wondering if there was something I have over looked. I tried making a global variable reference the variable but that didn't work.
What do you think
?
Does anyone know if Python supports non-volatile local variables

I was wondering if there was a way to keep the variable alive. I know that I can simply declare it as global, but then every function could read it. I was wondering if there was something I have over looked. I tried making a global variable reference the variable but that didn't work.
What do you think

def my_func(): global g_arr_my_func try: a += 1 except NameError: print("[my_func]: Exception (Name Error).") a = 0 # end try print("[my_func]: a =:", a) g_arr_my_func["a"] = a g_arr_my_func = {} g_arr_my_func["a"] = 0 my_func() my_func()
Output:[my_func]: Exception (Name Error).
[my_func]: a =: 0
[my_func]: Exception (Name Error).
[my_func]: a =: 0