Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 356
Zuckonit Avatar asked Mar 27 '13 09:03

Zuckonit


1 Answers

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.

like image 81
Daniel Roseman Avatar answered Feb 19 '23 13:02

Daniel Roseman