[英]How to import file from other folder Python?
我的结构是:
- Project
- Configuration
- __init__.py
- system.py
-GUI
- gui.py
- __init__.py
我想在gui.py
中使用system.py
。
所以我需要在gui.py
中导入system
。 我尝试通过执行以下操作添加__ init__.py
文件:
from .Configuration import system
但我有以下消息: attempted relative import with no known parent package
。
我也试过这个:
import sys; sys.path.insert(0, '../Configuration')
from system import system
但它也不起作用。
我能怎么做?
from Configuration import system
使用cd.../Project
(项目是当前目录)python -m GUI.gui
-m options
: python 搜索命名模块的sys.path
并将其内容作为__main__
模块执行。 与 -c 选项一样,当前目录将添加到 sys.path 的开头。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.