Asp Forum
Home
|
Login
|
Register
|
Search
Forums
>
comp.lang.python
Re: How to make an empty generator?
Steve Holden
2/19/2010 3:52:00 AM
Stephen Hansen wrote:
> On Thu, Feb 18, 2010 at 2:56 PM, Robert Kern <robert.kern@gmail.com
> <mailto:robert.kern@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
>
So add a comment to the yield statement so it reads
yield # force empty generator
I realise that Jacob Kaplan-Moss calls comments in the code "lies", but
the reader really only needs a small clue.
regards
Steve
--
Steve Holden +1 571 484 6266 +1 800 494 3119
PyCon is coming! Atlanta, Feb 2010
http://us....
Holden Web LLC
http://www.hold...
UPCOMING EVENTS:
http://holdenweb.event...
Servizio di avviso nuovi messaggi
Ricevi direttamente nella tua mail i nuovi messaggi per
Re: How to make an empty generator?
Inserendo la tua e-mail nella casella sotto, riceverai un avviso tramite posta elettronica ogni volta che il motore di ricerca troverà un nuovo messaggio per te
Il servizio è completamente GRATUITO!
x
Login to ForumsZone
Login with Google
Login with E-Mail & Password