简体   繁体   中英

import two python module from two different directory

My file structure like

    Myfolder/
           main/
              -main.py
           folder1/
              -file1.py
           folder2/
              -file2.py

I call file1.py with

sys.path.insert(0, '../file1')
import file1

that work, but i dont know how to do it again for file2.py. please help

You can do it in the following way without inserting in the sys path.

import .folder2.file2
import .folder1.file1

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