看下面的代码
生成器不支持索引及切片。参看第4行。
生成器不支持与list相加。
如果需要生成器结果那么最好用list expression,
-
>>> def get_some_stuff():
-
... pass
-
...
-
>>> def gen():
-
... return(something for something in get_some_stuff())
-
...
-
>>> print gen()[:2]
-
Traceback (most recent call last):
-
File "", line 1, in <module>
-
File "", line 2, in gen
-
TypeError: 'NoneType' object is not iterable
-
>>> print [5,6]+gen()
-
Traceback (most recent call last):
-
File "", line 1, in <module>
-
File "", line 2, in gen
-
TypeError: 'NoneType' object is not iterable
-
>>>
阅读(925) | 评论(0) | 转发(0) |