import next()python 2.5
发布时间:2020-09-25 09:12:36 所属栏目:Python 来源:互联网
导读:我正在使用itertools的成对配方的略微修改版本,看起来像这样 def pairwise(iterable): s - (s0,s1), (s1,s2), (s2, s3), ... a, b = tee(iterable) next(b, None) return zip(a, b) 现在我发现我需要使用python 2.5运行代码,其中next()函数
我正在使用itertools的成对配方的略微修改版本,看起来像这样 def pairwise(iterable): "s -> (s0,s1),(s1,s2),(s2,s3),..." a,b = tee(iterable) next(b,None) return zip(a,b) 现在我发现我需要使用python 2.5运行代码,其中next()函数抛出以下异常: < type'exceptions.NameError'>:未定义全局名称’next’ 有没有办法使用python 2.5的next()?或者我如何修改函数以使其无论如何工作? 解决方法您可以自己轻松提供此功能的定义:_sentinel = object() def next(it,default=_sentinel): try: return it.next() except StopIteration: if default is _sentinel: raise return default (编辑:鄂州站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- python – matplotlib.pyplot.imshow:在使用属性“sharex”
- 在Python 2.7.3中为numpy数组指定字段名称
- python – pymongo:MongoClient或Connection
- python – PyTables读取随机子集
- 【Tensorflow】Anaconda中激活tensorflow后如何使用
- python – Numpy.dot()维度未对齐
- python – 让namedtuple接受kwargs
- python – 有人可以解释为什么这会修复我的递归错误吗?
- django – 如何在保存之前使用PIL调整新上传的图像大小?
- python – 在OS X上安装Numba时出错
推荐文章
站长推荐
热点阅读