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

前端 未结 6 900
再見小時候
再見小時候 2021-01-01 08:15

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 pr

6条回答
  •  独厮守ぢ
    2021-01-01 09:08

    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.

提交回复
热议问题