Sometimes, I try to use a variable to name a function:
myVar = "something"
def myVar () :
pass
The function thus created is not something()
but myVar()
.
Same problem with global
:
myVar = "something"
global myVar
In this example, the variable isn't something
but it's myVar
.
Actually, my problem is similar; I want to create an attribute from a variable:
class myClass :
def __init__ (self) :
myVar = "something"
self.myVar = 1
Without surprise the attribute create in this example is self.myVar
, not self.something
.
Generally I try to avoid these kinds of problems by rethinking my code. But I would like to know if there is a way to do it?