Suppose I have a global variable a. And within a function definition, we also have a local variable named a. Is there any way to assign the value of the global variable to that of the local variable?
a = 'foo'
def my_func(a = 'bar'):
# how to set global a to value of the local a?
ain order to assign it to the global one. - tskuzzyWHY???!!1!11one|11!1ELEVE|\|1!?. To start, using globals is a bad practice, add a parameter to your func or make a class. Second, why would you want to use the same variable name in different contexts and relate their content. Can you try harder in making your code more ugly and confusing? - KurzedMetalclass Container(): pass,settings = Container(),settings.a = 'foo') and store my global variables in there. It's both mutable and distinguishable:if var1 is None: var1 = settings.var1,else: settings.var1 = var1and so on. - Nisan.H