我如何制作一个与root类似的文件名的python supodule目录
这个问题的标题似乎很混乱,我不知道该如何正确地言语,但这是情况的要旨。
说我有这种文件结构:
- 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论