2
I am creating a base class that keeps some common methods for daughter classes in Python3:
import abc
class Bot(abc.ABC):
def log(self, message):
bot = self.__name__
version = self.__dict__['version']
print(f"{bot}.{version}|{message}")
class ExampleBot(Bot):
pass
The intention is that, using inheritance it is possible to take the name of the class in which the method is called without having to replicate code... When I try to do that I get the following mistake:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 3, in log
AttributeError: 'ExampleBot' object has no attribute '__name__'
But if I try to call the property ExampleBot.__name__
direct it returns the expected result. What I need to do to get the name of the class in which the log method was called in this context?
Thanks boy! That’s exactly what I needed
– LeandroLuk