In a function
DEF FUN (): Pass
How do this function know who is called? It seems to be difficult in Class C language. But in Python is very simple
Import TRACEBACK
Def fun (): s = traceback.extract_stack () Print '% s invoked me!'% s [-2] [2]
This Fun function can know who calls it, and print it out, let's try:
>>> DEF A (): fun ()
>>> DEF B (): fun ()
>>> a () a invoked me! >>> b () b INVOKED ME! >>>
OK! How to apply this feature? Play all the imagination.