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


Groups > comp.lang.python > #7639 > unrolled thread

Re: break in a module

Started byMRAB <python@mrabarnett.plus.com>
First post2011-06-14 23:57 +0100
Last post2011-06-14 23:57 +0100
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: break in a module MRAB <python@mrabarnett.plus.com> - 2011-06-14 23:57 +0100

#7639 — Re: break in a module

FromMRAB <python@mrabarnett.plus.com>
Date2011-06-14 23:57 +0100
SubjectRe: break in a module
Message-ID<mailman.239.1308092256.11593.python-list@python.org>
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".

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web