Where is module being imported from?

前端 未结 8 1339
余生分开走
余生分开走 2020-12-07 19:57

Assuming I have two Python modules and path_b is in the import path:

# file: path_b/my_module.py
print \"I was imported from ???\"

#file: path_a/app.py
impo         


        
8条回答
  •  醉梦人生
    2020-12-07 20:23

    Also, if you have a function/class f from a module m you can get the path of the module using the module inspect

    import inspect
    from m import f
    
    print inspect.getmodule(f)
    

提交回复
热议问题