switch recipe?

Cliff Wells LogiplexSoftware1 at earthlink.net
Fri Jul 12 16:14:52 EDT 2002


On Fri, 2002-07-12 at 13:05, Mark McEahern wrote:
> > out of curiosity, what happens when n reaches the end of the
> > int/long/whatever that stores it?
> 
> My guess is this will run forever--if you let it.  <wink>
> 
> Perhaps it should allow an optional sentinel?  The assumption is the caller
> is responsible for using it wisely.

Or you could just change it to (untested):

def make_color_switch(color1, color2):
      def color_switch():
          i = 0
          while True:
              if i:
                  yield color2
              else:
                  yield color1
              i = not i
      return color_switch



Cliff






More information about the Python-list mailing list