Importing modules from a neighbouring folder in Python

前端 未结 3 1262
眼角桃花
眼角桃花 2020-12-16 17:06

I have put the question in the figure below:

EDIT The question put next to the figure is:

How do I make script_A1 import a function

3条回答
  •  春和景丽
    2020-12-16 17:20

    You can use a trick of adding the top folder to path:

    import sys
    sys.path.append('..')
    import folderB.something
    

    You can also use imp.load_source if you prefer.

提交回复
热议问题