在PyCharm下进行python项目编程,涉及到多目录的import,例如:
test_import需要使用her_class.py和his.class.py中的类。
只需要将gui目录在PyCharn环境下进行如下设置:
然后采用类似IDEA java项目中的package格式就可以了:
from a1.a2.a3.his_class import HisStudent
from a1.a2.her_class import HerStudent
first_student = HisStudent(“小明”, 20)
second_student = HerStudent(“小李”, 21)
if name == ‘main’:
print(first_student)
print(second_student)
python多目录的import
最新推荐文章于 2025-03-05 14:06:19 发布