Performance between ā€œfrom package importā€ and ā€œpackage importā€

Is there a performance difference between ā€œfrom import packageā€ and ā€œimport packageā€?

+7
source share
1 answer

No, the difference is not in performance. In both cases, the entire module must be analyzed, and any module level code will be executed. The only difference is the namespace: firstly, all the names of the imported module will become the names in the current module; in the second, only the package name is determined in the current module.

However, there is very rarely a good reason to use from foo import * . Either import the module or import specific names from it.

+15
source

All Articles