在python中,如何在不保留导入模块命名空间的情况下从其他模块导入所有类?

时间:2022-08-03 23:20:16

How do you import classes and methods from another module without retaining the former module namespace?

如何在不保留以前模块名称空间的情况下从其他模块导入类和方法?

I am current refactoring some legacy code and am frequently doing imports similar to these.

我目前正在重构一些遗留代码,并经常进行与此类似的导入。

from legacy_module import ClassA as ClassA
from legacy_module import ClassB as ClassB
from legacy_module import ClassC as ClassC
from legacy_module import methodA as methodA
from legacy_module import methodB as methodB

This is done so that the classes can be referenced as ClassA rather than legacy_module.ClassA.

这样做是为了可以将类引用为ClassA而不是legacy_module.ClassA。

In python, how do you import all of the classes and methods above in a single statement?

在python中,如何在单个语句中导入上面的所有类和方法?

from legacy_module import * as *

1 个解决方案

#1


27  

Use from legacy_module import * as your entire import.

使用legacy_module import *作为整个导入。

#1


27  

Use from legacy_module import * as your entire import.

使用legacy_module import *作为整个导入。