I have 2 classes:
class Logger: def __init__(self, name): self.name = name def log(self, log): # Этот класс должен перехватить имя класса, который его вызовет with open(self.name, "a+") as log_file: log_file.write(log) return log class SomeClass: def __init__(self): self.logger = Logger("log.txt") def log_some(self, message): print(message) self.logger.log(message) return message
And I need the Logger
class to be able to get the name of the class that called the method when called from another class of the log()
method. There is a way to get the name of the class in which the method is defined
self.__class__.__name__
But in this case, he will be useless to me. If more options?