是否可以从 python 代码中删除所有 __future__ 语句,而不会影响其使用 python 3.7.1 的功能?

Ali*_*eza 5 python import python-import python-3.x

__future__如果我使用的是 python 3.7.1,是否可以从源代码中删除以下语句而不影响其功能?

from __future__ import nested_scopes
from __future__ import generators
from __future__ import division
from __future__ import absolute_import
from __future__ import with_statement
from __future__ import print_function
from __future__ import unicode_literals
Run Code Online (Sandbox Code Playgroud)

jmd*_*_dk 5

这在lib/python3.7/__future__.py文件中记录。每个未来的导入(此处称为_Feature)都有两个 5 元组,分别指定可选版本和强制版本。此处,“强制发布”是指默认情况下哪个 Python 版本包含该功能。正如您通过上面的链接所看到的,所有强制版本都小于 3.7.1,除了两个,即barry_as_FLUFL(3.9.0 版本强制)和annotations(4.0.0 版本强制),第一个只是一个复活节彩蛋。

如果使用 Python 3.7.1 或更新版本,那么确实可以删除列表中所有未来的导入,并保证完全相同的代码执行。正如其他人评论的那样,这可能不是一个好主意,因为这会降低代码兼容性。