当许多.py文件导入重复的软件包时,如何保持规范的软件工程?

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

我编写了一些实用程序/工具.py文件,但它会导入许多重复的程序包。然后将这些.py文件导入其余的.py文件中例如,

# tool_a.py
import a
from b import b_1
import c
from e import e_1
# some implementations in a.py.
... ...
... ...

# tool_b.py
import b
import c
from d import d_1
# some implementations in b.py
... ...
... ...

# tool_c.py
import c
import d
import e
# some implementations c.py
... ...
... ...

# And there are so many tools files like this
... ...
... ...
# Class A
import tool_a
import tool_b
# some implementations in Class A
... ...
... ...


# Class B
import tool_a
import tool_c
# some implementations in Class B
... ...
... ...

# And there are so many Class implementation files will include these tool files just like here
... ...
... ...

因此,如果我只是在每个类文件中一个接一个地导入这些工具文件,它将导入许多重复的程序包,并导致依赖性问题。当然这是一个不好的方法,但是我不知道如何解决可怕的软件包依赖问题。有人可以帮助我还是提供一些教程?预先感谢。

python code-formatting python-packaging re-engineering
1个回答
1
投票

我认为您无需担心多个导入。如果您告诉python导入已经导入的模块,它将从最初导入时开始访问缓存的模块。最佳实践是仅将模块导入所需的位置,而不必担心同一模块是否导入了多个文件。

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