同一个项目下有多个文件夹,其中一个文件夹下新建两个py文件,分别是:py1.py;py2.py,内容分别为:
#!/usr/bin/python
# py1模块
def hello1():
print("i like python")
#!/usr/bin/python
# py2模块
def hello2():
print("trust me")
另一个文件夹下新建一个test.py文件,内容如下:(导入方式是:from temp import py1,py2)
from temp import py1,py2
py1.hello1()
py2.hello2()
此时执行结果:(正确的)
D:\PycharmProjects\test\venv\Scripts\python.exe D:/PycharmProjects/test/main/test.py
i like python
trust me
Process finished with exit code 0
若导入方式改为:from temp import *,会有错误
from temp import *
py1.hello1()
py2.hello2()
D:\PycharmProjects\test\venv\Scripts\python.exe D:/PycharmProjects/test/main/test.py
Traceback (most recen