关于python 中的__future__模块(from __future__ import ***)

在开头加上 from __future__ import print_function 这句之后,即使在python2.X,使用print就得像python3.X那样加括号使用。python2.X中print不需要括号,而在python3.X中则需要。
# python2.7
print "Hello world"

# python3
print("Hello world"

 如果某个版本中出现了某个新的功能特性,而且这个特性和当前版本中使用的不兼容,也就是它在该版本中不是语言标准,那么我如果想要使用的话就需要从 future模块导入。
       from __future__ import division
     from __future__ import absolute_import
     from __future__ import with_statement 。等等
  加上这些,如果你的python版本是python2.X,你也得按照python3.X那样使用这些函数


猜你喜欢

转载自blog.csdn.net/cyh153296/article/details/80824557