How can I determine whether a function was called using the function's name or by the name of an alias of that function?
I can inspect a function to get its name from within the body of a function by doing:
import inspect
def foo():
print(inspect.stack()[0][3])
foo() # prints 'foo'
source: Determine function name from within that function (without using traceback)
However, if I alias the function and try the same thing I get the original function name (not the alias)
bar = foo
bar() # prints 'foo'
I would like to be able to be able to do the following:
def foo():
print(... some code goes here ...)
bar = foo
foo() # prints 'foo'
bar() # prints 'bar'
l = [foo]; l[0]()
orsorted(some_list, key=l[0])
. – user2357112 supports Monical[0]()
should printl[0]
. – bunji