whoaminow() can be used inside a function to determine, at the time it is called, the name under which that function has been invoked.
NOTE: This solution is extremely brittle and provides very limited utility, as it stands. However, it does serve to highlight an interesting avenue for introspection, namely, the dis module.
Python, 66 lines
Alex Martelli's whoami() function (see http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/66062) allows you determine the "defined" name of the currently running function from inside that function. By "defined" name, I mean the name given to the function in it's def statement, e.g.,
def foo(): pass
has "defined" name 'foo'.
So, if you use whoami() inside foo(), it will tell you that the currently running function is 'foo'. But, if you alias foo, like so:
bar = foo
and then call bar (e.g., bar()), whoami() will still tell you that the currently running function is 'foo'. And this is certainly true, however, on occasion, you may prefer that whoami()'s report would return 'bar' instead. whoaminow() provides this behaviour.
NOTE: This recipe does not yet work properly for the test case fl0, above. This will return None, so if you use whoaminow(), be prepared to handle this case.
WARNING: This recipe will fail for functions with more than zero paremeters!