-3

How to get the name of function in if statement?
Is there any easy solution?
My case:

if is_wedge(df):
    fname = is_wedge.__name__
    img_path = Path(main_dir / 'images' / fname / img1.jpeg')
Batjl
  • 1
  • 2

1 Answers1

0

Could you use inspect.stack?

import inspect

def iswedge():
    stack = inspect.stack()    # Get stack info
    caller_info = stack[0]    # Get caller info
    fname = caller_info[3]    # Get function name
    img_path = Path(main_dir / 'images' / fname / img1.jpeg')
Linden
  • 531
  • 3
  • 12