import inspect def myfirstfunc(): print(inspect.currentframe().f_code.co_name) # OR print(inspect.stack()[0][3]) myfirstfunc()