您可以在不影响功能的情况下删除那些__future__导入,但是删除它们不是必需的,并且会停止与早期python版本的兼容性。在
此外,正如@deceze在评论中所暗示的那样,其他进口商品可能有所不同。例如,from __future__ import annotations在Python<;=4.0中是only enabled,因此添加/删除该行将影响功能:Since this change breaks compatibility, the new behavior needs to be
enabled on a per-module basis in Python 3.7 using a __future__ import:
from __future__ import annotations
It will become the default in Python 4.0.
正如@jmd_dk指出的,您实际上可以在__future__模块中找到这些信息。我写了一个简短的脚本来摘录:import __future__
import ast
import sys
print('Python version:', sys.version_info)
sys_t = sys.version_info[:3]
s = '__future__ import {} {} for you; the version: {} vs. your version: {}'
for name in __future__.all_feature_names:
optional, mandatory, _ = ast.literal_eval(str(getattr(__future__, name)).lstrip('_Featur'))
optional, mandatory = optional[:3], mandatory[:3]
print('\nName: {}'.format(name))
tmp = [None, None, optional, sys_t]
if optional <= sys_t:
tmp[:2] = 'is', 'included'
else:
tmp[:2] = 'not', 'included'
print(s.format(*tmp))
tmp[2] = mandatory
if mandatory <= sys_t:
tmp[:2] = 'is', 'fixed'
else:
tmp[:2] = 'not', 'fixed'
print(s.format(*tmp))
在我的系统上,它输出:
^{pr2}$
当Python>;=3.8引入了__future__导入(在我编写本文时还没有引入),删除这些导入并在python3.7上运行显然会影响功能。在