Calling variable functions based on name I would like to be able to iterate through a loop and call two sets of functions based on ..something - something that I can iterate through, such as a string list. Here is an example of my situation:

def Check(name):
    return not_important

def DrawA():
    draw_a_stuff
def DrawB():
    draw_b_stuff
def DrawC():
    draw_c_stuff

list = [ "A","B","C" ]
for type in list:
    if Check(type):
        continue

    func = get_function_in_this_module( "Draw" + type )
    func() # call drawing function


What would be the simplest way to do something like this? It will be used to draw UI sections of a panel based on which sections are visible/available.
Put references to the functions in a dictionary, using the names you want to invoke them by as keys, and the references as value.

functions={"A":DrawA, # The function name *must not* be followed by parentheses
"B":DrawB,
"C":DrawC
}


Then, you only have to check if type is in the dictionary, and call the function using functions[type](...).

(Edited for clarity in regard to the lack of parentheses)