Force importing module from current directory

后端 未结 3 1300
情歌与酒
情歌与酒 2020-12-25 12:59

I have package p that has modules a and b. a relies on b:

b.py contents:



        
3条回答
  •  长发绾君心
    2020-12-25 13:12

    Because there is an __init__.py file in /p. This file tells Python: "All modules in this folder are in the package p".

    As long as the __init__.py file exists, you can import b as p.b, no matter where you are.

    So the correct import in b.py would be: import p.a

提交回复
热议问题