lundi 16 août 2021

In python, Two functions calls some same workflows, how to distinguish the origin function at bottom?

I have two python functions A() and B(), they both call f1(), and f1() calls f2()... In f4(), I want to get the origin function name(A or B), Is there any smart way? I thought I can add a param for each functions, but it makes my codes quite ugly. These functions are in different files and some start in new Thread, I also read some doc about context but I'm not sure if it works here.

def A():
    f1()

def B():
    f1()


def f1():
    f2()

def f2():
    f3()

def f3():
    f4()

def f4():

    if call_from_A:
        print(123)
    else:
        print(456)

Aucun commentaire:

Enregistrer un commentaire