(mod_name, alter_argv=True)
return _run_code(code, main_globals, None,
                     "__main__", mod_spec)
Runs the designated module in the __main__ namespace

       Note that the executed module will have full access to the
       __main__ namespace. If this is not desirable, the run_module()
       function should be used to run the module code in a fresh namespace.

       At the very least, these variables in __main__ will be overwritten:
           __name__
           __file__
           __cached__
           __loader__
           __package__
Runs the designated module in the __main__ namespace
Runs the designated module in the __main__ namespace
def _run_module_as_main(mod_name, alter_argv=True):
    """Runs the designated module in the __main__ namespace

       Note that the executed module will have full access to the
       __main__ namespace. If this is not desirable, the run_module()
       function should be used to run the module code in a fresh namespace.

       At the very least, these variables in __main__ will be overwritten:
           __name__
           __file__
           __cached__
           __loader__
           __package__
    """
    try:
        if alter_argv or mod_name != "__main__": # i.e. -m switch
            mod_name, mod_spec, code = _get_module_details(mod_name, _Error)
        else:          # i.e. directory or zipfile execution
            mod_name, mod_spec, code = _get_main_module_details(_Error)
    except _Error as exc:
        msg = "%s: %s" % (sys.executable, exc)
        sys.exit(msg)
    main_globals = sys.modules["__main__"].__dict__
    if alter_argv:
        sys.argv[0] = mod_spec.origin
    return _run_code(code, main_globals, None,
                     "__main__", mod_spec)
def _run_module_as_main ( mod_name , alter_argv = True ) : try : if alter_argv or mod_name != "__main__" : # i.e. -m switch mod_name , mod_spec , code = _get_module_details ( mod_name , _Error ) else : # i.e. directory or zipfile execution mod_name , mod_spec , code = _get_main_module_details ( _Error ) except _Error as exc : msg = "%s: %s" % ( sys . executable , exc ) sys . exit ( msg ) main_globals = sys . modules [ "__main__" ] . __dict__ if alter_argv : sys . argv [ 0 ] = mod_spec . origin return _run_code ( code , main_globals , None , "__main__" , mod_spec )