On Wed, Jun 15, 2011 at 10:51 AM, Eric Snow <ericsnowcurren...@gmail.com> wrote:
>  if condition_1:
>      ...
>      return
>  if condition_2:
>      ...
>      return
>
>  # now do my expensive module stuff
>
>  # finally handle being run as a script
>  if __name__ == "__main__":
>      ...
>
The best way I can think of is:


def expensive_stuff_1():
    ...

def expensive_stuff_2():
    ...

if not condition_1:
    expensive_stuff_1()
if not condition_2:
    expensive_stuff_2()


Depending on what exactly you're doing, this might make perfect sense,
or might be a useless indentation level of its own. If the expensive
stuff divides nicely into units, where each unit is governed by one
condition, it might work out well that way; you could use the same
functions to build your 'if __main__' section too.

ChrisA
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to