我如何制作一个与root类似的文件名的python supodule目录

发布于 2025-01-30 13:29:33 字数 782 浏览 3 评论 0原文

这个问题的标题似乎很混乱,我不知道该如何正确地言语,但这是情况的要旨。

说我有这种文件结构:

- main.py
- util.py
- submodules
  - module_folder
    - sub_main.py
    - util.py

main.py

import submodules.module_folder.sub_main

util.py

print("Util in root")

subsodules/module_folder/sub_main.py

import util

/util.py。

print("Util in submodules.module_folder.util")

subsodules/ module_folder >'s 导入util load subsodules/module_folder/util.py.py而不是util.py.py在目录的根部?

限制:

  • 我无法更改Module_folder中的任何文件。它们将是可读的

应用程序上下文: 我要以这种方式构建的原因是因为我正在构建一个功能,该功能将使用户导入任意的git子模块,该插座可以具有随机的文件结构和路径。

The title of this question may seem very confusing and I didn't know how to word it properly, but here's the gist of the situation.

Say I have this kind of file structure:

- main.py
- util.py
- submodules
  - module_folder
    - sub_main.py
    - util.py

main.py

import submodules.module_folder.sub_main

util.py

print("Util in root")

submodules/module_folder/sub_main.py

import util

submodules/module_folder/util.py

print("Util in submodules.module_folder.util")

The question is: How can I make submodules/module_folder/sub_main.py's import util load submodules/module_folder/util.py instead of util.py in the root of the directory?

Restrictions:

  • I can't change any files in module_folder. They are to be readonly

Application Context:
The reason that I want to build it this way is because I am building a feature that will let the user import arbitrary git submodules which can have random file structures and paths.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文