break in a module

Ethan Furman ethan at stoneleaf.us
Tue Jun 14 19:28:37 EDT 2011


MRAB wrote:
> On 14/06/2011 23:28, Eric Snow wrote:
>> 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".

To me, too -- too bad it doesn't work:

c:\temp>\python32\python early_abort.py
   File "early_abort.py", line 7
     return
        ^
SyntaxError: 'return' outside function

~Ethan~



More information about the Python-list mailing list