使用Python在其他文件夹中导入程序

Fra*_*els 0 python

我想从2个不同的文件夹导入Python程序:

  • Prog1 从路上 /home/francis/docs/folder1/
  • Prog2 从路上 /home/francis/docs/folder2/

如何在我的主程序中导入这两个程序/home/francis/docs/folder3/

Jdo*_*dog 5

将它添加到Prog3的顶部:

import sys
sys.path.append('/home/francis/docs/folder1/')
sys.path.append('/home/francis/docs/folder2/')
import Prog1
import Prog2
Run Code Online (Sandbox Code Playgroud)