Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #7639
| Date | 2011-06-14 23:57 +0100 |
|---|---|
| From | MRAB <python@mrabarnett.plus.com> |
| Subject | Re: break in a module |
| References | <BANLkTinfUsHXuF5j5XjTMhiQXQKNi4ZSGA@mail.gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.239.1308092256.11593.python-list@python.org> (permalink) |
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".
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: break in a module MRAB <python@mrabarnett.plus.com> - 2011-06-14 23:57 +0100
csiph-web