Like so:
class Foo(object):
def MethodName():
pass
print type(Foo()).__name__
# Foo
Or,
foo=Foo()
print type(foo).__name__
# Foo
(Note -- that only works on new style classes, not legacy classes. It obviously only works if you know what to call to instantiate the class)
If all you have is reference to a method, you can use inspect (Thx Alex Martelli):
import inspect
def get_class_from_method(meth):
for cls in inspect.getmro(meth.im_class):
if meth.__name__ in cls.__dict__: return cls
return None
>>> mn=Foo().MethodName
>>> get_class_from_method(mn).__name__
Foo
Or, for a user defined method, you can do:
>>> mn.im_class.__name__
Foo