class.__name__
is the name of the class or type.
It can also be written in modules, classes, and built-in functions, so it can be written more widely than func_name
.
import time
time.time.func_name #Error
time.time.__name__ #'time'
However, you can give warning in Python 3
sys._getframe([depth]) returns frame object
from the stack top by depth
on the call stack.
If depth
is greater than call stack, ValueError
occurs.
import sys
this_function_name = sys._getframe().f_code.co_name
© 2024 OneMinuteCode. All rights reserved.