首页 > 解决方案 > 导入不同目录中的文件 [PYTHON]

问题描述

假设我有一个具有以下结构的示例项目:

-app
    -venv (dir)
    -randomPythonFile.py
    -myPythonFiles (dir)
        -helloworld.py

我想导入文件 helloworld.py - 我知道我必须将目录 myPythonFiles 添加到我可以轻松完成的解释器路径中,但是我如何将这些更改推送到 git 以便其他人不必手动将其添加到他们的路径?

标签: pythonimportinterpreter

解决方案


您需要__init__.py目录中的文件。

from myPythonFiles import helloworld

推荐阅读