def _run_module_as_main(mod_name, set_argv0=True):
 try:
  (loader, code, fname) = _get_module_details(mod_name)
 except ImportError as exc:
  if set_argv0:
   info = str(exc)
  else:
   info = ("can't find '__main__.py' in %r" % sys.argv[0])
  msg = ('%s: %s' % (sys.executable, info))
  sys.exit(msg)
 pkg_name = mod_name.rpartition('.')[0]
 main_globals = sys.modules['__main__'].__dict__
 if set_argv0:
  sys.argv[0] = fname
 return _run_code(code, main_globals, None, '__main__', fname, loader, pkg_name)

def _run_module_as_main ( mod_name , set_argv0 = True ) : try : ( loader , code , fname ) = _get_module_details ( mod_name ) except ImportError as exc : if set_argv0 : info = str ( exc ) else : info = ( "can't find '__main__.py' in %r" % sys . argv [ 0 ] ) msg = ( '%s: %s' % ( sys . executable , info ) ) sys . exit ( msg ) pkg_name = mod_name . rpartition ( '.' ) [ 0 ] main_globals = sys . modules [ '__main__' ] . __dict__ if set_argv0 : sys . argv [ 0 ] = fname return _run_code ( code , main_globals , None , '__main__' , fname , loader , pkg_name )
runs the designated module in the __main__ namespace these __*__ magic variables will be overwritten: __file__ __loader__ .