简体   繁体   中英

Importing python file from other directory

I have a following directory structure:

                                parentDirectory
                                       |
                   -----------------------------------------
                  |                                         |
                 Task                                    Configs
                   - pythonFile1.py                         - Config1.py
                                                            - Config2.py

The Configuration files have few configuration constants defined inside a class.

Now, I want to import the configuration files from Configs directory into the python file under Tasks directory and make use of constants defined inside the class in each config file.

I had tried with adding(after reading through few answers) -

sys.path.insert(0,'/home/MyName/parentDirectory/Tasks')

inside the config files.

Since I am new to python, I don't know to what extent I am correct in adding the above lines.

Please help!

我认为您倒退了:如果您希望“任务”能够导入“配置”,则需要向“任务”添加代码以将Configs路径插入sys.path

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM