python3.7.1使用_在不影响使用python3.7.1的功能的情况下,是否可以从python代码中删除所有的ufuture_uu语句?...

您可以在不影响功能的情况下删除那些__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&gt;=3.8引入了__future__导入(在我编写本文时还没有引入),删除这些导入并在python3.7上运行显然会影响功能。在

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值