I know Python introspection feature are powerful, what I can't seem to figure out is how to get the name of the current class.

Example:

class Foo:
   def bar(self):
        print(classname)

Then my output should be Foo. Bonus points if I can get which module it resides in too.
Thanks!

Edited 3 Years Ago by mike_2000_17: Fixed formatting

>>> class Thing(object):
	pass

>>> t = Thing()
>>> dir(t)
['__class__', '__delattr__', '__dict__', '__doc__', '__getattribute__', '__hash__', '__init__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__str__', '__weakref__']
>>> print t.__class__
<class '__main__.Thing'>

>>> print t.__module__
__main__

Jeff

I know Python introspection feature are powerful, what I can't seem to figure out is how to get the name of the current class.

Example:

class Foo:
   def bar(self):
        print(classname)

Then my output should be Foo. Bonus points if I can get which module it resides in too.
Thanks!

The Python module inspect should contain your desired functions.

Edited 3 Years Ago by mike_2000_17: Fixed formatting

This question has already been answered. Start a new discussion instead.