我有一个要使用itertools.imap()解决的问题。但是,在将itertools导入IDLE shell中并调用了itertools.imap()之后,IDLE shell告诉我itertools没有属性imap。怎么了
>>> import itertools
>>> dir(itertools)
['__doc__', '__loader__', '__name__', '__package__', '__spec__', '_grouper', '_tee', '_tee_dataobject', 'accumulate', 'chain', 'combinations', 'combinations_with_replacement', 'compress', 'count', 'cycle', 'dropwhile', 'filterfalse', 'groupby', 'islice', 'permutations', 'product', 'repeat', 'starmap', 'takewhile', 'tee', 'zip_longest']
>>> itertools.imap()
Traceback (most recent call last):
File "", line 1, in
itertools.imap()
AttributeError: 'module' object has no attribute 'imap'
最佳答案
itertools.imap() is in Python 2, but not in Python 3.
Actually, that function was moved to just the map function in Python 3 and if you want to use the old Python 2 map, you must use list(map()).