#coding=utf8 import sys def test(): gf = sys._getframe print dir(gf()) print 'function name:',sys._getframe(1).f_code.co_name if sys._getframe(1).f_code.co_name != 'a': print 'Error' else: print 'Ok' def a(): test() def b(): test() class t(object): def a(self): test() if __name__ == '__main__': a() b() tt = t() tt.a()