On Thu, Feb 18, 2010 at 2:56 PM, Robert Kern <robert.k...@gmail.com> wrote:
> class once(object): > def __init__(self, func, *args, **kwds): > self.func = func > self.args = args > self.kwds = kwds > > def __iter__(self): > return self > > def next(self): > self.func(*self.args, **self.kwds) > raise StopIteration() > Hmm, yeah. I'd probably tweak it into a decorator and name it sideeffect_only or something, but yeah, that's the right approach at least. My motivation is clarity, I can just see a colleague a year from now asking me, "... what the hell is return / yield?" and although this is more expensive, its less clear to me. Thanks. --S
-- http://mail.python.org/mailman/listinfo/python-list