obj.__class__.__name__
will get you any objects name, so you can do this:
class Clazz():
def getName(self):
return self.__class__.__name__
Usage:
>>> c = Clazz()
>>> c.getName()
'Clazz'
More Related Contents:
- Python Classes with methods [closed]
- Why does it say that my instance has no attribute x?
- Understanding Python super() with __init__() methods [duplicate]
- Python function overloading
- Saving and loading multiple objects in pickle file?
- difference between variables inside and outside of __init__()
- How to keep track of class instances?
- Is it possible to overload Python assignment?
- Is it possible to make abstract classes in Python?
- Nested classes’ scope?
- What is the __dict__.__dict__ attribute of a Python class?
- Why do attribute references act like this with Python inheritance? [duplicate]
- Possibilities for Python classes organized across files? [closed]
- Calling functions from a Tkinter Frame to another
- How can I pickle a dynamically created nested class in python?
- Does Python have class prototypes (or forward declarations)?
- How to properly overload the __add__ method?
- What is the purpose of python’s inner classes?
- Difference between ‘cls’ and ‘self’ in Python classes?
- The scope of names defined in class block doesn’t extend to the methods’ blocks. Why is that?
- Python: How do I make a subclass from a superclass?
- What is the benefit to using a ‘get function’ for a python class? [closed]
- How to implement a binary search tree in Python?
- Class (static) variables and methods
- Is it possible to make abstract classes?
- Should I use instance or class attributes if there will only be one instance? [closed]
- Should I use a class or dictionary?
- Python: deleting a class attribute in a subclass
- Python using methods from other classes
- Provide __classcell__ example for Python 3.6 metaclass