function iternb (not used yet, but it's more usefull in tree than in stash)

This commit is contained in:
Romain Bignon 2010-08-25 13:21:08 +02:00
commit 185a6e91a2

View file

@ -87,3 +87,13 @@ def iter_fields(obj):
if not isinstance(attribute, types.MethodType):
yield attribute_name, attribute
def iternb(it, nb=0):
"""
Iter 'nb' times on the generator
"""
i = 0
for v in it:
if i >= nb:
raise StopIteration()
yield v
i += 1