Python Tricks: : Accessing class and function names at runtime

# You can get the name of
# an object's class as a
# string:

>>> class MyClass: pass

>>> obj = MyClass()
>>> obj.__class__.__name__

# Functions have a
# similar feature:

>>> def myfunc(): pass

>>> myfunc.__name__

Leave a Reply

Your email address will not be published. Required fields are marked *