why do we invoke print after importing print_function (in Python 2.6)
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.
print_function
is a FeatureName
not be confused with the print
built-in function itself.
It is a feature that is available from the future so that you can use the built-in function that it can provide.
Other Features include:
all_feature_names = [
"nested_scopes",
"generators",
"division",
"absolute_import",
"with_statement",
"print_function",
"unicode_literals",
]
There are specific reasons as when you migrate your code to next higher version, your program will remain as such as use the updated feature instead of the __future__
version. Also if it were function name or the keyword itself, it may cause confusion to the parser.