Get the class that initiated a call from a function that is called
Somewhere in the sources of Zope I've seen a technique similar to this, to get to the locals of the caller object. Although interesting to know, actually deploying this technique makes the code hard to understand, so I would advice against it. Still, I'm recording it here, for my own reference.
import sys
def do():
frame = sys._getframe(1)
caller = frame.f_locals['self']
print caller.secret
class A(object):
secret = "Hello world"
def __init__(self):
do()
if __name__ == "__main__":
A()