我的IDLE无法将itertools.izip()识别为函数 [英] My IDLE does not recognize itertools.izip() as a function

查看:71
本文介绍了我的IDLE无法将itertools.izip()识别为函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

>>> 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'

推荐答案

在Python 3中,itertools模块中没有izip函数,因为内置的zip函数(不需要任何导入即可)访问)现在的行为类似于Python 2中的itertools.izip.因此,要使您的代码正常工作,只需使用zip而不是itertools.izip.

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.

您还提到了string.maketrans的问题.那是Python 3中一个模块中不再存在的另一个函数,它现在是str类的一种方法:str.maketrans.但是请注意,它的行为与Python 2中的string.maketrans有点不同,因为对字符串的translate方法采用不同的参数(字典而不是256个字符的字符串).

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).

听起来您可能正在遵循针对Python 2编写的指南,但是使用Python 3运行代码.这可能会造成混淆,因为该语言的主要版本之间存在重大变化.您应该尝试查找针对Python 3的指南.我不建议您使用Python 2进行编码,除非您确实必须遵循当前指南.

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.

这篇关于我的IDLE无法将itertools.izip()识别为函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆