Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to obtain the function name of current function?

(defun foo ()
    (send-to-debug-log "Error. Function terminated." (get-current-function-name)))

I currently do this:

(defun foo ()
    (send-to-debug-log "Error. Function terminated." 'foo)))

Hard coding the function name seems not to be a good practice. Any suggestion to implement the get-current-function-name or get-function-name-that-call-me.

like image 663
tom Avatar asked Mar 10 '16 03:03

tom


People also ask

How do you get a function name inside a function in Python?

Method 1: Get Function Name in Python using function. func_name.

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.

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.

What is Python __ name __?

The __name__ variable (two underscores before and after) is a special Python variable. It gets its value depending on how we execute the containing script. Sometimes you write a script with functions that might be useful in other scripts as well. In Python, you can import that script as a module in another script.


1 Answers

(defun foo ()
  (send-to-debug-log "Error. Function terminated." (nth 1 (backtrace-frame 2))))
like image 61
Michael Albinus Avatar answered Oct 04 '22 11:10

Michael Albinus