Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #7663

Re: break in a module

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 <rosuav@gmail.com>
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 <BANLkTikmNbNgSzirxO3Jbhs4898+OD2Efw@mail.gmail.com>
References <BANLkTinfUsHXuF5j5XjTMhiQXQKNi4ZSGA@mail.gmail.com> <4DF7E75E.9000907@mrabarnett.plus.com> <mailman.240.1308093309.11593.python-list@python.org> <qaWdnQmQzemLaWrQnZ2dnUVZ5vidnZ2d@giganews.com> <BANLkTikmNbNgSzirxO3Jbhs4898+OD2Efw@mail.gmail.com>
Date Wed, 15 Jun 2011 11:33:47 +1000
Subject Re: break in a module
From Chris Angelico <rosuav@gmail.com>
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 <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.249.1308101630.11593.python-list@python.org> (permalink)
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

Show key headers only | View raw


On Wed, Jun 15, 2011 at 10:51 AM, Eric Snow <ericsnowcurrently@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

Back to comp.lang.python | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

Re: break in a module Ethan Furman <ethan@stoneleaf.us> - 2011-06-14 16:28 -0700
  Re: break in a module Erik Max Francis <max@alcyone.com> - 2011-06-14 16:51 -0700
    Re: break in a module Eric Snow <ericsnowcurrently@gmail.com> - 2011-06-14 18:51 -0600
      Re: break in a module Ben Finney <ben+python@benfinney.id.au> - 2011-06-15 11:33 +1000
        Re: break in a module Eric Snow <ericsnowcurrently@gmail.com> - 2011-06-14 20:21 -0600
          Re: break in a module Erik Max Francis <max@alcyone.com> - 2011-06-16 15:09 -0700
        Re: break in a module Dave Angel <davea@ieee.org> - 2011-06-15 00:02 -0400
      Re: break in a module Erik Max Francis <max@alcyone.com> - 2011-06-16 15:07 -0700
        Re: break in a module Chris Angelico <rosuav@gmail.com> - 2011-06-17 09:27 +1000
          Re: break in a module Erik Max Francis <max@alcyone.com> - 2011-06-16 16:29 -0700
            Re: break in a module Eric Snow <ericsnowcurrently@gmail.com> - 2011-06-16 18:00 -0600
            Re: break in a module Chris Angelico <rosuav@gmail.com> - 2011-06-17 10:01 +1000
              Re: break in a module Erik Max Francis <max@alcyone.com> - 2011-06-16 18:13 -0700
                Re: break in a module Ethan Furman <ethan@stoneleaf.us> - 2011-06-16 19:17 -0700
                Re: break in a module Erik Max Francis <max@alcyone.com> - 2011-06-16 21:21 -0700
                Re: break in a module Ian Kelly <ian.g.kelly@gmail.com> - 2011-06-16 22:53 -0600
        Re: break in a module Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-06-17 00:48 +0000
          Re: break in a module Chris Angelico <rosuav@gmail.com> - 2011-06-17 10:57 +1000
            Re: break in a module Erik Max Francis <max@alcyone.com> - 2011-06-16 18:21 -0700
              Re: break in a module Ethan Furman <ethan@stoneleaf.us> - 2011-06-16 19:11 -0700
              Re: break in a module Ian Kelly <ian.g.kelly@gmail.com> - 2011-06-16 19:58 -0600
                Re: break in a module Erik Max Francis <max@alcyone.com> - 2011-06-16 21:24 -0700
                Re: break in a module Ian Kelly <ian.g.kelly@gmail.com> - 2011-06-16 22:50 -0600
                Re: break in a module Erik Max Francis <max@alcyone.com> - 2011-06-16 22:20 -0700
                Re: break in a module Chris Angelico <rosuav@gmail.com> - 2011-06-17 15:56 +1000
                Re: break in a module Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-06-17 06:00 +0000
                Re: break in a module Erik Max Francis <max@alcyone.com> - 2011-06-17 00:09 -0700
                Re: break in a module Cameron Simpson <cs@zip.com.au> - 2011-06-18 12:36 +1000
                Re: break in a module Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-06-18 03:50 +0000
                Re: break in a module Chris Angelico <rosuav@gmail.com> - 2011-06-18 14:31 +1000
                Re: break in a module Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-06-18 04:49 +0000
                Re: break in a module Chris Angelico <rosuav@gmail.com> - 2011-06-18 15:06 +1000
                Re: break in a module Cameron Simpson <cs@zip.com.au> - 2011-06-21 20:04 +1000
                Re: break in a module Eric Snow <ericsnowcurrently@gmail.com> - 2011-06-17 00:25 -0600
    Re: break in a module Chris Angelico <rosuav@gmail.com> - 2011-06-15 11:33 +1000

csiph-web