为什么python没有__future__
库替换map
imap
,range
替换xrange
等?是否可以写一个?
答案 0 :(得分:8)
自Python 2.6以来有future_builtins
个模块:
from future_builtins import filter, map, zip
答案 1 :(得分:4)
无需__future__
导入:
from itertools import imap as map
range = xrange
修改:如果你想在一行中完成其中几个,你可以
from itertools import imap as map, ifilter as filter, izip as zip
range = xrange; input = raw_input
答案 2 :(得分:2)
如果您想这样做,为什么不将以下内容添加到PYTHONSTARTUP文件中?
import itertools
filter = itertools.ifilter
map = itertools.imap
slice = itertools.islice
zip = itertools.izip
range = xrange
input = raw_input