My IDLE does not recognize itertools.izip() as a function

谁说我不能喝 提交于 2020-01-01 08:49:18

问题


>>> itertools.izip('ABCD', 'xy')
Traceback (most recent call last):
  File "<pyshell#55>", line 1, in <module>
    itertools.izip('ABCD', 'xy')
AttributeError: 'module' object has no attribute 'izip'

回答1:


In Python 3, there is no izip function in the itertools module because the builtin zip function (which doesn't require any imports to access) now behaves like itertools.izip did in Python 2. So, to make your code work, just use zip instead of itertools.izip.

You also mentioned an issue with string.maketrans. That's another function that is no longer in a module in Python 3. It's now a method of the str class: str.maketrans. Note however that its behavior is a bit different than string.maketrans in Python 2, as the translate method on strings takes different arguments (a dictionary instead of a 256-character string).

It sounds like you may be following a guide written for Python 2, but using Python 3 to run your code. This can be confusing, as there were signficant changes between the major versions of the language. You should try to find a guide that targets Python 3 instead. I don't recommend using Python 2 for your coding unless you really must follow your current guide.



来源:https://stackoverflow.com/questions/32261698/my-idle-does-not-recognize-itertools-izip-as-a-function

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!