Hi, in this class many methods share common code.

class Foo(object):
    def m1(self):
        if self.foo:
            pass # m1 do something
        elif self.bar:
            pass # m1 do something else
        else:
            pass # m1 do something different

    def m2(self):
        if self.foo:
            pass # m2 do something
        elif self.bar:
            pass # m2 do something else
        else:
            pass # m2 do something different

    # def m_n(self):
        pass # same conditionals, different implementation

I'm wondering if I have to duplicate the if/elif/else for each method.
Does Python 2.7 provide a way to factor out this common structure?
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to