0

Can use self.__class__.__name__ inside an instance method, but I need to do something like this

class Utilities:
    className = Utilities.__name__

I am hoping to assign the class name to className (and do something with it later) to a class variable, but unable to figure it out.

Any ideas anyone? TIA

scorpion35
  • 944
  • 2
  • 12
  • 30
  • Thank you! The decorator approach looks promising, but trying to avoid adding it on every class created (there will be many). Guess that will be the only option if there is none other available? – scorpion35 May 26 '23 at 01:33
  • If this is going to be a behavior of several classes you can create a "base" class and make those classes subclasses of the "base". You can also use [metaclasses](https://stackoverflow.com/questions/100003/what-are-metaclasses-in-python). – Davi A. Sampaio May 26 '23 at 01:38

0 Answers0