[如果有同名软件包,如何在Python 3中加载模块?

问题描述 投票:0回答:1

[在处理某些旧版Python包时,我注意到有一个子包shadowing一个具有相同名称的模块。这是显示问题的简化文件层次结构:

t/
t/__init__.py
t/u/
t/u.py
t/u/__init__.py

您可以看到,有一个python模块t/u.py和一个子包t/u/,看起来像是标准import语句加载了该子包:

$ python3
Python 3.5.2 (default, Oct  8 2019, 13:06:37) 
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import t.u
__init__.py
>>> 

但是,有没有办法导入模块t/u.py

python-3.x python-import python-3.5
1个回答
0
投票

也许从t导入u从t导入u起作用

© www.soinside.com 2019 - 2024. All rights reserved.