Python : which importing module is calling my function at runtime
Question: I don't know if there is a way to get the information I want, so maybe there
isn't. Anyway, here is my question:

I have a module, say "m.py", with a function , say "def f(): ..."

Now imagine some other modules are importing m.py

in f, I would like to know which module is calling me, at runtime.

is that possible ?

thanks for your help


Answer: 
    import sys,inspect,os
    _logLevel = 10
    def debugPrint(*args,**kwargs):
        if _logLevel > kwargs.get('required_level',0):
            args = list(args)
            info = inspect.stack()[1]
            info = tuple([os.path.basename(info[1]),info[2]])
            args.insert(0,"%s %s:"%info)
            sys.stdout.write(" ".join("%s"%arg for arg in args))
    
    debugPrint("Hello world!")
    

is a method I like to use that might help you

