在一些代码中看到‘from __future__ import print_function’这个语句,经查找资料,此句的用途及用法记录如下:
用途:把python新版本中print_function函数的特性导入到当前版本。如,在python2环境下,使用此句,则可以超前使用python3的print函数了。
(以上参考:https://zhuanlan.zhihu.com/p/28641474 )
用法:只能放置于当前运行代码片段的最开头。否则会报错如下 “ SyntaxError: from __future__ imports must occur at the beginning of the file”:
【用如下例子解释为什么是当前运行的代码片段:
(这样import就不会报错,也是奇怪。。。)
】