H2ONaCl H2ONaCl - 6 months ago 22
Python Question

why do we invoke print after importing print_function (in Python 2.6)

To get the 3.0 print function we do the following in Python 2.6:

from __future__ import print_function

But to use the function we invoke print() not print_function(). Is this just an inconsistency or is there a good reason for this?

Why not the following:

from __future__ import print


The reason is that when you import from __future__ you're really just setting a flag that tells the interpreter to behave a bit differently than usual -- in the case of print_function, the print() function is made available in place of the statement. The __future__ module is thus "special" or "magic" -- it doesn't work like the usual modules.