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>;=3.8引入了__future__導入(在我編寫本文時還沒有引入),刪除這些導入并在python3.7上運行顯然會影響功能。在
總結
以上是生活随笔為你收集整理的python3.7.1使用_在不影响使用python3.7.1的功能的情况下,是否可以从python代码中删除所有的ufuture_uu语句?...的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 排序:快速排序与归并排序
- 下一篇: 排序:冒泡排序与选择排序