def whoaminow():
    "returns name of called calling function"
    import sys, dis

    # get frame where calling function is called
    frame = sys._getframe(2)

    # get code and next to last instruction from frame
    code = frame.f_code
    lasti = frame.f_lasti-3

    # redirect ouput of disassemble (stdout)
    oldout = sys.stdout
    sys.stdout = open('log','w')
    dis.disassemble(code, lasti)
    sys.stdout.close()
    sys.stdout = oldout  # restore stdout

    # retrieve current byte code line
    fd = open('log')
    for line in fd.xreadlines():
        if line.startswith('-->'):
            break
    else: # couldn't find name
        line = None
    fd.close()
    
    # isolate function name
    if line is not None:
        funcname = line.split()[-1][1:-1]
    else: 
        funcname = None
    return funcname
returns name of called calling function
recipes/Python/200892_Determining_current_functions_name_at_time_it/recipe-200892.py