How to access a local variable with the same name as a global variable after the global keyword?
var = 0
def foo():
var = 1
global var
var += 1
#now how i do change the scope to the local variable without deleting var
How to access a local variable with the same name as a global variable after the global keyword?
var = 0
def foo():
var = 1
global var
var += 1
#now how i do change the scope to the local variable without deleting var
Give the local variable a different name. global
applies for the entirety of the function, you can't switch back and forth as you go. The best you could do is cheap hacks to access the global (globals()['var']
) while leaving the name local, but don't do this. Use different names.