从其他 python 文件夹导入一个模块

时间:2021-04-05 20:16:59

标签: python-3.x

我有一个具有以下路径的项目:

shift/
     Code/
          __init__.py
          mymain.py
          run.py
     Test/
         __init__.py
         tester.py
         runtester.py

     requirments.txt

mymain.py 中有一个我需要从 tester.py 导入的类。因此,在 tester.py 中,我按照以下代码导入类,但它们都不起作用。

from Code.mymain import NewClass
from .mymain import NewClass
from mymain import NewClass
from shift.Code.mymain import NewClass

我也尝试在 tester.py 中插入路径:

cwd = os.getcwd()
sys.path.insert(0, cwd)

但是还是很困惑为什么它不知道我的文件

1 个答案:

答案 0 :(得分:0)

试试这个

<div th:if="${goalMet}">
<p> abc123 </p>
<script th:inline="javascript">
    function congratulate() {
      alert("Congratulations on achieving your Goal!");
    }
    congratulate()
</script>
</div>

更多详情:importing files from different folder

相关问题