Path: csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!weretis.net!feeder1.news.weretis.net!feeder.erje.net!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.002 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'own.': 0.03; 'wed,': 0.03; 'subject:module': 0.04; 'indentation': 0.07; '__name__': 0.09; 'nicely': 0.09; 'units,': 0.09; 'way;': 0.09; 'def': 0.12; 'am,': 0.14; 'received:209.85.214.174': 0.14; 'received:mail- iw0-f174.google.com': 0.14; 'wrote:': 0.14; '"__main__":': 0.16; 'doing,': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'header:In-Reply-To:1': 0.21; 'stuff': 0.22; '\xa0if': 0.23; 'script': 0.27; 'message-id:@mail.gmail.com': 0.28; 'received:209.85.214': 0.28; 'module': 0.30; 'useless': 0.30; 'to:addr:python-list': 0.33; '...': 0.34; 'expensive': 0.34; 'sense,': 0.35; 'too.': 0.37; 'received:google.com': 0.37; 'received:209.85': 0.37; 'skip:e 20': 0.37; 'think': 0.38; 'could': 0.38; 'run': 0.38; 'eric': 0.38; 'subject:: ': 0.38; 'received:209': 0.39; 'to:addr:python.org': 0.39; 'best': 0.60; 'your': 0.60; 'perfect': 0.64; "'if": 0.84; '10:51': 0.84; 'condition,': 0.84; 'divides': 0.84; 'snow': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:in-reply-to:references:date :message-id:subject:from:to:content-type:content-transfer-encoding; bh=GaYSooGrat6/Ftz4tgntzp+BuPzxwBqE2SeDSUNj9OI=; b=fZr2HxluYcN75QO7Ri/P+/npscQyW3+G1MCzstLLDz5wi+UHBe3r7nklaFECSzvqfB kOcqFPg5RF6Z1E+OEtN5wnSfcRxrwwrW1jp7jFzjeRCBAy/EL0PzN4ayQ/8LhWJrWyJy nF7WJeENCTjDw6XahzJZSHUh9uodauGttyqyg= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; b=UjaHz6mVHbHs/qZvx+HtgHhxSkoq8B06ARv5z0DnUOQAQgG6FVdZxJulHJqMnd6AcX aQQAj0U9hUWviHcfq0Td3TTt41peXPFsf1/eleojzRvbSlWHdsL+K5c73pI3bLI6ukiD JJfKH+QrhLPhircWFk7kqNxzxvufx69p3Lyn8= MIME-Version: 1.0 In-Reply-To: References: <4DF7E75E.9000907@mrabarnett.plus.com> Date: Wed, 15 Jun 2011 11:33:47 +1000 Subject: Re: break in a module From: Chris Angelico To: python-list@python.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 38 NNTP-Posting-Host: 82.94.164.166 X-Trace: 1308101630 news.xs4all.nl 49039 [::ffff:82.94.164.166]:52637 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:7663 On Wed, Jun 15, 2011 at 10:51 AM, Eric Snow w= rote: > =A0if condition_1: > =A0 =A0 =A0... > =A0 =A0 =A0return > =A0if condition_2: > =A0 =A0 =A0... > =A0 =A0 =A0return > > =A0# now do my expensive module stuff > > =A0# finally handle being run as a script > =A0if __name__ =3D=3D "__main__": > =A0 =A0 =A0... > 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