Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!feeder.news-service.com!xlned.com!feeder5.xlned.com!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.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'else:': 0.03; 'subject:module': 0.04; 'sys': 0.05; 'indentation': 0.07; '__name__': 0.09; 'from:addr:python': 0.09; 'thoughts?': 0.09; 'this:': 0.10; 'wrote:': 0.14; '"__main__":': 0.16; 'from:addr:mrabarnett.plus.com': 0.16; 'from:name:mrab': 0.16; 'message-id:@mrabarnett.plus.com': 0.16; 'met,': 0.16; 'received:84.92': 0.16; 'received:84.92.122': 0.16; 'received:84.92.122.60': 0.16; 'received:84.93': 0.16; 'received:84.93.230': 0.16; 'reply-to:addr:python-list': 0.16; 'header:In-Reply-To:1': 0.21; 'stuff': 0.22; 'body.': 0.23; 'code': 0.24; 'received:84': 0.25; 'modules': 0.26; 'thanks.': 0.27; 'import': 0.29; 'module': 0.30; 'to:addr:python-list': 0.33; 'break': 0.33; 'rather': 0.34; 'header:User-Agent:1': 0.35; 'reply-to:addr:python.org': 0.35; 'certain': 0.36; 'beginning': 0.37; 'something': 0.37; 'eric': 0.38; 'execute': 0.38; 'subject:: ': 0.38; 'some': 0.38; 'sometimes': 0.39; 'skip:s 20': 0.39; 'rest': 0.39; 'to:addr:python.org': 0.39; 'header:Reply-To:1': 0.72; 'reply-to:no real name:2**0': 0.72; 'snow': 0.91 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: ApUGANnm901UXebj/2dsb2JhbABSmA6ORXeIdb9uhiYEliKLFg Date: Tue, 14 Jun 2011 23:57:34 +0100 From: MRAB User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.2.17) Gecko/20110414 Thunderbird/3.1.10 MIME-Version: 1.0 To: python-list@python.org Subject: Re: break in a module References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list Reply-To: python-list@python.org 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: 1308092257 news.xs4all.nl 49048 [::ffff:82.94.164.166]:38803 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:7639 On 14/06/2011 23:28, Eric Snow wrote: [snip] > With modules I sometimes have code at the beginning to do some small > task if a certain condition is met, and otherwise execute the rest of > the module body. Here's my main use case: > > """some module""" > > import sys > import importlib > import util # some utility module somewhere... > > if __name__ == "__main__": > name = util.get_module_name(sys.modules[__name__]) > module = importlib.import_module(name) > sys.modules[__name__] = module > else: > # do my normal stuff at 1 indentation level > > I would rather have something like this: > > """some module""" > > import sys > import importlib > import util # some utility module somewhere... > > if __name__ == "__main__": > name = util.get_module_name(sys.modules[__name__]) > module = importlib.import_module(name) > sys.modules[__name__] = module > break > > # do my normal stuff at 0 indentation level > > So, any thoughts? Thanks. > To me, the obvious choice would be "return", not "break".