Use the __name__ Property to Get the Function Name in Python __name__ . It will then return the function name as a string. The below example declares two functions, calls them, and prints out their function names. Note that this solution also works with the imported and pre-defined functions.
In Python, any written function can be called by another function. Note that this could be the most elegant way of breaking a problem into chunks of small problems.
Python help() function is used to get the documentation of specified module, class, function, variables etc. This method is generally used with python interpreter console to get details about python objects.
Keyword def that marks the start of the function header. A function name to uniquely identify the function. Function naming follows the same rules of writing identifiers in Python. Parameters (arguments) through which we pass values to a function. They are optional.
For my logging purpose i want to log all the names of functions where my code is going
Does not matter who is calling the function , i want the the function name in which i declare this line
import inspect
def whoami():
return inspect.stack()[1][3]
def foo():
print(whoami())
currently it prints foo
, i want to print whoami
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With