Chris
Chris

Reputation: 4317

In python, how do you import all classes from another module without keeping the imported module's namespace?

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.

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

from legacy_module import * as *

Upvotes: 34

Views: 49513

Answers (1)

Jordan
Jordan

Reputation: 32522

Use from legacy_module import * as your entire import.

Upvotes: 68

Related Questions