[Tutor] introspecting an object for method's name?

Serdar Tumgoren zstumgoren at gmail.com
Sun Oct 18 23:43:22 CEST 2009


Hi everyone,
I'm trying to create a generic logging function, and I'm able to get
at the name of the module and class using the built-in attributes
__module__, __class__, and __name__.

But I wasn't sure how to also grab the name of the function or method,
so that when an error occurs, I can log the name of the failing method
as well.

I'd like to do something like:

class Dummy(object):
    get_name(self):
        print "%s, %s, %s" % (self.__module__,
self.__class__.__name__, METHOD_NAME)

Is there a way to dynamically grab the name of the method? E.g.,
"get_name" in the above class.

Feels like I'm overlooking something obvious....

Serdar


More information about the Tutor mailing list