Controlling a generator the pythonic way

Peter Hansen peter at engcorp.com
Sat Jun 11 13:24:14 EDT 2005


Thomas Lotze wrote:
> Which is, as far as the generator code is concerned, basically the same as
> passing a mutable object to a (possibly standalone) generator. The object
> will likely be called self, and the value is stored in an attribute of it.

Fair enough, but who cares what the generator code thinks?  It's what 
the programmer has to deal with that matters, and an object is going to 
have a cleaner interface than a generator-plus-mutable-object.

> Probably this is indeed the best way as it doesn't require the programmer
> to remember any side-effects.
> 
> It does, however, require a lot of attribute access, which does cost some
> cycles.

Hmm... "premature optimization" is all I have to say about that.

-Peter



More information about the Python-list mailing list