break in a module

Erik Max Francis max at alcyone.com
Tue Jun 14 19:51:50 EDT 2011


Ethan Furman wrote:
> 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

Nor should it.  There's nothing to return out of.

-- 
Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/
  San Jose, CA, USA && 37 18 N 121 57 W && AIM/Y!M/Skype erikmaxfrancis
   There is _never_ no hope left. Remember.
    -- Louis Wu



More information about the Python-list mailing list