== Finding the name of your caller in Python One of the things that would be useful in an [[access tracer AttributeTracingClass]] is reporting not just what was accessed, but where it was accessed from. A basic starter for this is knowing what function called you. CPython has enough introspection faculties to give you this information, but it's not entirely documented how to dig it out. The big tool for this is the [[inspect module http://docs.python.org/lib/module-inspect.html]], and we can use it to define a function: import inspect def getcallerinfo(): fr = inspect.currentframe() try: fr = fr.f_back.f_back if fr is None: return "" fi = inspect.getframeinfo(fr, 0) if fi[2] == "": return "(%s:%d)" % (fi[0], fi[1]) else: return "%s() (%s:%d)" % (fi[2], fi[0], fi[1]) finally: del fr This returns something like '_barfunc() (foo.py:30)_', which means that the function that called _getcallerinfo()_ was called by _barfunc()_, specifically the code at line 30 of _foo.py_. Technically we don't need to call _inspect.getframeinfo()_ to obtain this information (we could just use ((fr.f_code.co_filename)) and so on directly, since they're [[documented http://docs.python.org/lib/inspect-types.html]]), but it handles some peculiar magic with the file name for us. (Needless to say, this is probably specific to CPython; I would be surprised if the same code worked in [[Jython http://www.jython.org/]] or [[IronPython http://www.ironpython.com/]] or the like. Since all of this is documented, it is at least likely to be portable across different versions of CPython and to keep working in future ones.)