Zuckonit
Zuckonit

Reputation: 685

Performance between "from package import *" and "import package"

Is there any performance difference between from package import * and import package?

Upvotes: 8

Views: 200

Answers (1)

Daniel Roseman
Daniel Roseman

Reputation: 599630

No, the difference is not a question of performance. In both cases, the entire module must be parsed, and any module-level code will be executed. The only difference is in namespaces: in the first, all the names in the imported module will become names in the current module; in the second, only the package name is defined in the current module.

That said, there's very rarely a good reason to use from foo import *. Either import the module, or import specific names from it.

Upvotes: 16

Related Questions