diff --git a/weboob/tools/misc.py b/weboob/tools/misc.py index 94ba7acd..b8422af8 100644 --- a/weboob/tools/misc.py +++ b/weboob/tools/misc.py @@ -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