Как в Python узнать имя функции в которой выполняется код? Желательно не устанавливая дополнительные модули.
Например 1:
class Test:
def func_1():
print(f'Print from {name_this_function}')
def func_2():
print(f'Print from {name_this_function}')
def func_3():
print(f'Print from {name_this_function}')
test = Test()
test.func_1()
test.func_2()
test.func_3()
Пример 2:
class Test:
def func_1():
self.where_are_you()
def func_2():
self.where_are_you()
def func_3():
self.where_are_you()
def where_are_you():
if current_func == 'func_1':
print('Print from func_1')
elif current_func == 'func_2':
print('Print from func_2')
elif current_func == 'func_2':
print('Print from func_2')
test = Test()
test.func_1()
test.func_2()
test.func_3()
При выполнении кода хочу видеть такой вывод:
Print from func_1
Print from func_2
Print from func_3
class Test: def func_1(): self.where_are_you() def func_2(): self.where_are_you() def func_3(): self.where_are_you() def where_are_you(): if current_func == 'func_1': print('Print from func_1') elif current_func == 'func_2': print('Print from func_2') elif current_func == 'func_2': print('Print from func_2') test = Test() test.func_1() test.func_2() test.func_3()