0

I write something look like simple translator to logic lang of Mindustry game. This logic have a variables like all langs. I have a wrapper of variable which makes some stuff. And for do this I must get variable named by user. Now, I just take one more argument as name in class constructor. But this not look nice. I want find some method for get the name seted by user. While I make this like this

some = Variable('some', 12)
# Constructor of Variable class
def __init__(self, name : str, value : Union(Variable, int, float, str, bool)=None):
    Command.__init__(self)
    self.name = name
    self.value = value
    # For previously identified variable. To not make excess command.
    if self.value is not None:
        if isinstance(value, Variable):
            self.value = value.name
        self._Command__add_to_storage()

How I can get this name in class constructor without take's one more arg?

I tried make this like was said in a comments

self.name = f'{self=}'.partition('=')[0]
# or with varname lib
self.name = nameof(self)

But this return 'self'

Nawot
  • 34
  • 1
  • 5

0 Answers0