itertools.cycle().next()? [英] itertools.cycle().next()?

查看:111
本文介绍了itertools.cycle().next()?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,我在Python 2.6.6中使用了itertools.cycle().next()方法,但是现在我更新到了3.2,我注意到itertools.cycle()对象没有方法next().

Well, I was using itertools.cycle().next() method with Python 2.6.6, but now that I updated to 3.2 I noticed that itertools.cycle() object has no method next().

我用它在Spinner类的spin()方法中循环了一个字符串.因此,如果我们循环元组('|', '/', '-', '\\', '|', '/', '-'),它将打印:|/-\|/-|/等等...

I used it to cycle a string in the spin()method of a Spinner class. So if we cycle the tuple ('|', '/', '-', '\\', '|', '/', '-'), it'll print: |, /, -, \ , |, /, -, |, / and so on...

我搜索了Python 3.0、3.1和3.2的发行说明,但没有发现任何变化.什么时候变了?有没有其他简单的方法可以实现与以前相同的功能?

I've searched the release notes of Python 3.0, 3.1 and 3.2 and didn't noticed any change on this. When this have changed? Is there any simple alternative to achieve the same functionality as before?

谢谢.

推荐答案

iter.next()已在python 3中删除.改用next(iter).因此,在您的示例中,将itertools.cycle().next()更改为next(itertools.cycle())

iter.next() was removed in python 3. Use next(iter) instead. So in your example change itertools.cycle().next() to next(itertools.cycle())

这里有一个此处的好示例以及其他各种移植到python 3的技巧.它还比较了python 2.x和python 3.x中的其他next()习惯用法

There is a good example here along with various other porting to python 3 tips. It also compares various other next() idioms in python 2.x vs python 3.x

这篇关于itertools.cycle().next()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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