def CastTo(ob, target):
 if hasattr(target, 'index'):
  if ('CLSID' not in ob.__class__.__dict__):
   ob = gencache.EnsureDispatch(ob)
  if ('CLSID' not in ob.__class__.__dict__):
   raise ValueError('Must be a makepy-able object for this to work')
  clsid = ob.CLSID
  mod = gencache.GetModuleForCLSID(clsid)
  mod = gencache.GetModuleForTypelib(mod.CLSID, mod.LCID, mod.MajorVersion, mod.MinorVersion)
  target_clsid = mod.NamesToIIDMap.get(target)
  if (target_clsid is None):
   raise ValueError(("The interface name '%s' does not appear in the same library as object '%r'" % (target, ob)))
  mod = gencache.GetModuleForCLSID(target_clsid)
  target_class = getattr(mod, target)
  target_class = getattr(target_class, 'default_interface', target_class)
  return target_class(ob)
 raise ValueError

def CastTo ( ob , target ) : if hasattr ( target , 'index' ) : if ( 'CLSID' not in ob . __class__ . __dict__ ) : ob = gencache . EnsureDispatch ( ob ) if ( 'CLSID' not in ob . __class__ . __dict__ ) : raise ValueError ( 'Must be a makepy-able object for this to work' ) clsid = ob . CLSID mod = gencache . GetModuleForCLSID ( clsid ) mod = gencache . GetModuleForTypelib ( mod . CLSID , mod . LCID , mod . MajorVersion , mod . MinorVersion ) target_clsid = mod . NamesToIIDMap . get ( target ) if ( target_clsid is None ) : raise ValueError ( ( "The interface name '%s' does not appear in the same library as object '%r'" % ( target , ob ) ) ) mod = gencache . GetModuleForCLSID ( target_clsid ) target_class = getattr ( mod , target ) target_class = getattr ( target_class , 'default_interface' , target_class ) return target_class ( ob ) raise ValueError
cast a com object to another interface .