John Gordon <gor...@panix.com> wrote: > But lately I've been preferring this style: > > def myMethod(self, arg1, arg2): > > if some_bad_condition: > return bad1 > > elif some_other_bad_condition: > return bad2 > > elif yet_another_bad_condition: > return bad3 > > do_some_useful_stuff() > return good1
For more than 2 tests in a function like this, I'd probably use dictionary dispatch: def myMethod(self, arg1, arg2): branches = dict( cond1: bad1, cond2: bad2, cond3: bad3 ) cond = <expression> if cond == cond_good: do_some_useful_stuff() exitCode = good1 else: exitCode = branches[cond] return exitCode -- http://mail.python.org/mailman/listinfo/python-list