文件结构
pythontest
│ outmain.py
│
└─module
inmain.py
test.py
__init__.py
包内调用
inmain.py
from test import add
if __name__ == "__main__":
c = add(1, 2)
print(c)
这里from test import add
我尝试换成from module.test import add
会报错,不明白为什么。
包外调用
outmain.py
from module.test import add
c = add(1, 2)
print(c)
这里使用from module.test import add
就可以