Toggle

Travis Griggs travisgriggs at gmail.com
Thu Oct 9 01:38:26 EDT 2014


On Oct 8, 2014, at 9:57 PM, Gregory Ewing <greg.ewing at canterbury.ac.nz> wrote:

> Seymore4Head wrote:
>> I want to toggle between color="Red" and color="Blue"


Don’t forget polymorphic dispatch…

class Red(object):
    def toggle(self):
        return Blue()

class Blue(object):
    def toggle(self):
        return Red()


Blue().toggle().toggle().toggle().toggle().toggle() :)

--
Travis Griggs
Objologist
"Some of them wanted to sell me snake oil and I'm not necessarily going to dismiss all of these, as I have never found a rusty snake." --Terry Pratchett




More information about the Python-list mailing list