在Python中,你如果在某一个版本的Python想使用未来版本中的功能,可以使用如下语法实现:

from __future__ import futurename

这条语句必须放在module文件的第一行才行。

 

比如想在Python 2.X中使用Python 3.X的print函数,那么,只需要在模块文件第一行加入:

from __future__ import print_function

 

但是,怎样才能知道futurename有哪些呢?一个方法如下:

import __future__   # 导入__future模块

dir(__future__)   # 列举出__future__模块中的属性
['with_statement', 'print_function', 'absolute_import '...]

 

相关文章:

  • 2022-03-07
  • 2021-09-20
  • 2022-12-23
  • 2021-07-04
  • 2021-06-25
  • 2021-07-30
  • 2021-12-26
猜你喜欢
  • 2022-12-23
  • 2021-12-22
  • 2022-01-11
  • 2021-12-27
  • 2022-12-23
  • 2022-02-08
相关资源
相似解决方案