>>> 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
- 62
- 391
- 407

- 181
- 1
- 1
- 4
-
4Which version of Python are you using? In Python 3, the builtin function `zip` behaves like `itertools.izip` did in Python 2. – Blckknght Aug 28 '15 at 02:32
-
Blckknght is right. If you don't know how to find python version, see here: http://stackoverflow.com/questions/9079036/detect-python-version-at-runtime – Filip Malczak Aug 30 '15 at 08:07
-
@Blckknght Hi Blckknght, I am using version 3.4.3. You can see that along the top bar of the shell window too. I am having the same problem with string.maketrans(…). see: – Alexander Wright Aug 30 '15 at 15:21
-
>>> trans = string.makestrans('ae','bx') Traceback (most recent call last): File "
", line 1, in – Alexander Wright Aug 30 '15 at 15:21trans = string.makestrans('ae','bx') AttributeError: 'module' object has no attribute 'makestrans'
1 Answers
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.

- 100,903
- 11
- 120
- 169
-
Thank you responding. I was in fact following an online course video on sliderule that must have been recorded using Python 2. – Alexander Wright Sep 08 '15 at 00:35