break in a module
MRAB
python at mrabarnett.plus.com
Tue Jun 14 18:57:34 EDT 2011
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".
More information about the Python-list
mailing list