So let's say I have this function with a lot of variable setting:
def set_variables():
var_a = 10
var_b = 200
and these variables need to be set in multiple functions and accessed via their var name. Is there a way to create this function s.t. after it's call the parent function that calls it has var_a and var_b without having to return them? The function above is an example, but in reality there are a lot of variables so it's not really viable to have something like the below.
def parent_function():
var_a, var_b, ... = set_variables()
ideally I'd like something like
def parent_function():
set_variables()
# do some code with var_a or var_b
Or maybe even return a dict of key, val and automatically generate variables of key name set to val.
So for example
def parent_function():
var_dict = set_variables()
some_func_to_auto_set_vars_from_dict(var_dict)
# Do something with var_a or var_b
set_variablesreturn a value, just return a singledictinstead of multiple values.set_variables()were to simply return whatever variables necessary, you could then just pass those variables toparent_function().