我在 Python 的 itertools 中找不到 imap()
- 作者: 卟忘15530746
- 来源: 51数据库
- 2022-10-28
问题描述
我有一个问题想用 itertools.imap() 解决.但是,当我在 IDLE shell 中导入 itertools 并调用 itertools.imap() 后,IDLE shell 告诉我 itertools 没有属性 imap.怎么了?
I have a problem that I want to solve with itertools.imap(). However, after I imported itertools in IDLE shell and called itertools.imap(), the IDLE shell told me that itertools doesn't have attribute imap. What's going wrong?
>>> 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 "<pyshell#13>", line 1, in <module> itertools.imap() AttributeError: 'module' object has no attribute 'imap'
推荐答案
itertools.imap() 在 Python 2 中,但不在 Python 3 中.
itertools.imap() is in Python 2, but not in Python 3.
实际上,该函数在 Python 3 中被移到了 map 函数中,如果你想使用旧的 Python 2 地图,你必须使用 list(map())代码>.
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()).
推荐阅读
热点文章
Discord.py(重写)on_member_update 无法正常工作
0
Discord.py 在 vc 中获取用户分钟数
0
discord.py 重写 |为我的命令出错
0
Discord.py rewrite 如何 DM 命令?
0
播放音频时,最后一部分被切断.如何解决这个问题?(discord.py)
0
在消息删除消息 Discord.py
0
如何使 discord.py 机器人私人/直接消息不是作者的人?
0
(Discord.py) 如何获取整个嵌入内容?
0
Discord bot 尽管获得了许可,但不能提及所有人
0
Discord.py discord.NotFound 异常
0
