Advantage of partial import

What is the advantge of partial import?

from __future__ import print_function 

vs

import __future__ 

The latter is slower and costs more memory?

Specifically for __future__, these statements are not interchangeable. The from __future__ import version activates special code inside the parser that the other doesn’t.

The performance difference is negligible, and if anything, the former is worse for performance if you only consider the statement in isolation.

Partial imports lead to more readable latter on if you use the object.

1 Like