How to know who is importing me in python?

前端 未结 3 937
挽巷
挽巷 2021-01-02 03:30

How can I find out what file is importing a particular file in python?

Consider the following example:

#a.py
import cmn
....

#b.py
import cmn
...

#         


        
3条回答
  •  余生分开走
    2021-01-02 03:53

    You'd need to install an import hook that tracks all imports. See PEP 302 and http://docs.python.org/dev/py3k/library/importlib.html. However, as the comments above point out, there is probably a better way to structure your code.

提交回复
热议问题