I have a python class defined in a module1.py file:
class MBVar(): def __init__(self, var_type, expression): self.var_type = var_type self.expression = expression ... ecc ... I would like to be able to write in a main *.py file:
from module1 import MBVar X = MBVar('integer', 6) and add to my MBVar class:
self.name = ??? in such a way that: self.name = 'X'. Is it possible to do this??
Thanks
X = MBVar('integer', 6); Y = X; Z = Y? What would you expect the.nameattribute ofX,YandZto contain?MBVarhas no way of knowing the name that you bind the instance to, unless you explicitly tell it. And as I mentioned earlier, what should the.namebecome if you bind the instance to multiple names?print([MBVar('integer', i) for i in range(5)]). That creates 5MBVarinstances, and none of them are actually bound to a name. So what would you want your magical naming operation to do in that situation?