Python Forum
Non Volatile Local Variables?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Non Volatile Local Variables?
#1
Hi all,

Does anyone know if Python supports non-volatile local variables Think ?

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 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
Reply


Messages In This Thread
Non Volatile Local Variables? - by microphone_head - Mar-10-2019, 05:50 PM
RE: Non Volatile Local Variables? - by micseydel - Mar-10-2019, 06:42 PM
RE: Non Volatile Local Variables? - by buran - Mar-10-2019, 07:34 PM
RE: Non Volatile Local Variables? - by micseydel - Mar-10-2019, 08:02 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020