python - 导入不同目录中的文件 [PYTHON]
问题描述
假设我有一个具有以下结构的示例项目:
-app
-venv (dir)
-randomPythonFile.py
-myPythonFiles (dir)
-helloworld.py
我想导入文件 helloworld.py - 我知道我必须将目录 myPythonFiles 添加到我可以轻松完成的解释器路径中,但是我如何将这些更改推送到 git 以便其他人不必手动将其添加到他们的路径?
解决方案
您需要__init__.py
目录中的文件。
from myPythonFiles import helloworld
推荐阅读
- python - 使用 discord.py 获取公会的所有者
- javascript - Rails 实时聊天:仅使用纯 JavaScript 实现它是否安全?
- python - 找到 0 个有缺陷的示例,但在目录中有 10 个图像 | 找到 0 个完美的例子 |
- matlab - 查找所有满足约束的值并在 MATLAB 中可视化约束
- python - Python 中的 `in` 运算符用于比较什么?
- android - 如何在flutter中为play store构建一个已知的apk?
- python - 模块“scipy.sparse”在网状虚拟环境中没有属性“linalg”错误
- c++ - 为什么 loadFromFile 在读取位置时会产生访问冲突?
- laravel - Laravel Jetstream Inertia 非授权路线
- android - 使用 Retrofit、okhttp 和 picasso 缓存图像和字符串