def EnsureDispatch(prog_id, bForDemand=1):
 disp = win32com.client.Dispatch(prog_id)
 if (not disp.__dict__.get('CLSID')):
  try:
   ti = disp._oleobj_.GetTypeInfo()
   disp_clsid = ti.GetTypeAttr()[0]
   (tlb, index) = ti.GetContainingTypeLib()
   tla = tlb.GetLibAttr()
   mod = EnsureModule(tla[0], tla[1], tla[3], tla[4], bForDemand=bForDemand)
   GetModuleForCLSID(disp_clsid)
   import CLSIDToClass
   disp_class = CLSIDToClass.GetClass(str(disp_clsid))
   disp = disp_class(disp._oleobj_)
  except pythoncom.com_error:
   raise TypeError('This COM object can not automate the makepy process - please run makepy manually for this object')
 return disp

def EnsureDispatch ( prog_id , bForDemand = 1 ) : disp = win32com . client . Dispatch ( prog_id ) if ( not disp . __dict__ . get ( 'CLSID' ) ) : try : ti = disp . _oleobj_ . GetTypeInfo ( ) disp_clsid = ti . GetTypeAttr ( ) [ 0 ] ( tlb , index ) = ti . GetContainingTypeLib ( ) tla = tlb . GetLibAttr ( ) mod = EnsureModule ( tla [ 0 ] , tla [ 1 ] , tla [ 3 ] , tla [ 4 ] , bForDemand = bForDemand ) GetModuleForCLSID ( disp_clsid ) import CLSIDToClass disp_class = CLSIDToClass . GetClass ( str ( disp_clsid ) ) disp = disp_class ( disp . _oleobj_ ) except pythoncom . com_error : raise TypeError ( 'This COM object can not automate the makepy process - please run makepy manually for this object' ) return disp
given a com prog_id .