From 185a6e91a2f37d6f203e94919a96c88a434cfaec Mon Sep 17 00:00:00 2001 From: Romain Bignon Date: Wed, 25 Aug 2010 13:21:08 +0200 Subject: [PATCH] function iternb (not used yet, but it's more usefull in tree than in stash) --- weboob/tools/misc.py | 10 ++++++++++ 1 file changed, 10 insertions(+) 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