从同一文件夹导入 python 包时如何修复功能重叠?

How to fix overlap of functions when importing python packages from the same folder?

我有一个名为 Libs 的文件夹,其中包含两个文件(database.pykeyManagementService.py),我想将其作为库导入到 Libs 文件夹之外的另一个文件中。为此,我在 Libs 文件夹中创建了一个 __init__.py,如下所示:

from Libs.database import *
from Libs.keyManagmentService import *

我将库导入到 Libs 之外的文件的方式是这样的:

import Libs as db 
import Libs as kms

但是,问题是数据库文件中的函数与 KeyManagementService 文件中的函数重叠,因此如果我尝试使用 db 为例,kms 中的函数也会出现.由于缺乏更好的措辞,我如何使这些库独立?谢谢!

如果您清除 __init__.py 中的内容(但保留空文件),您应该能够

from Libs.database import the_exact_names_you_need
from Libs.keyManagementService import the_names_you_need_from_this_file