0 Replies - 277 Views - Last Post: 11 July 2008 - 02:18 PM

#1 ibbie   User is offline

  • New D.I.C Head
  • member icon

Reputation: 2
  • View blog
  • Posts: 19
  • Joined: 07-July 08

Find the name of the function that called a function

Posted 11 July 2008 - 02:18 PM

Description: Sometimes it can be handy to know what function is calling a function - say, for debugging and/or logging purposes. This snippet gives a brief example of how to go about this.
import sys, inspect

def name_of_caller():
    return inspect.getframeinfo(sys._getframe(1), context=0)[2]

def example():
    return name_of_caller()

print example()

Is This A Good Question/Topic? 0
  • +

Page 1 of 1