[python-win32] Accessing a COM-objects type name

Wikström Sven sven.wikstrom at scania.com
Tue Mar 13 14:31:58 CET 2007


Hi!

What is the most appropriate way to access a COM-objects type name in Python like Vbscript's "TypeName" function?

The concerned COM-objects are developed using .NET interop.
I have previously solved it, with .NET 1.1 COM-objects, by calling the COM exposed derived "System.Object.GetType()" method from Python. This is not possible after moving to .NET 2.0, as the "Type" only seem to have IUnknown (not Idispatch). Still works in Vbscript though with "TypeName"...!

>> dotNet11 = win32com.client.Dispatch("DotNet11.ComObject")
>> print dotNet11.GetType()
DotNet11.ComObject
>>
>> otherDotNet11 = dotNet11.CreateOther()
>> print otherDotNet11.GetType()
DotNet11.OtherComObject

>> dotNet20 = win32com.client.Dispatch("DotNet20.ComObject")
>> print dotNet20.GetType()
<COMObject DotNet20.ComObject>
>>
>> otherDotNet20 = dotNet20.CreateOther()
>> print otherDotNet20.GetType()
<COMObject CreateOther>

Thanks and best regards.

/Sven


More information about the Python-win32 mailing list