使用yield关键字,好处大大胜于return, 因为yield返回的不是序列,而是一个生成器对象,next()接受,可以实现边生成数值,边传送处理,而return 只能等所有数据都取完,才能处理,效率有跟大差异。 一般可以用在parse 方法里面代替return 方法·给piplines.py返回值。
经过测试,发现yield效率远远高于return 一起的。