1. 程式人生 > >python 獲取當前函式名和行號

python 獲取當前函式名和行號

sys._getframe([depth])

Return a frame object from the call stack. If optional integer depth is given, return the frame object that many calls below the top of the stack. If that is deeper than the call stack, ValueError is raised. The default for depth is zero, returning the frame at the top of the call stack.

CPython implementation detail: This function should be used for internal and specialized purposes only. It is not guaranteed to exist in all implementations of Python.


<span style="font-family:Arial;font-size:18px;"><strong>sys._getframe(1).f_code.co_name
sys._getframe().f_back.f_code.co_name</strong></span>