Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

get current function name inside that function using python

Tags:

People also ask

How do you print a function name in Python?

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.

Can you call a function inside a function in Python?

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.

How do you find the information of a function in Python?

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.

What is @function name in Python?

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