introspection?

Neal Norwitz nnorwitz at gmail.com
Thu Aug 19 00:09:00 EDT 2004


Jim Benson <jbenson at lowell.edu> wrote in message news:<mailman.1907.1092865845.5135.python-list at python.org>...
> 
> How does one get the class and method name from within
> a method?

    >>> import sys
    >>> class C:
    ...   def foo(self): 
    ...     print self.__class__.__name__, sys._getframe().f_code.co_name
    ...
    >>> C().foo()
    C foo

Neal



More information about the Python-list mailing list