Python COM Variant problem

Annie aichia77 at
Fri Feb 27 10:31:49 CET 2004

I am trying to call a COM object which expects a variant datatype to
be passed in to the COM API object. However, I get "<COMObject
<unknown>>" and the program fails.

Below is my code in Python, and the same code in VB which is working

I guess this is a variant problem with python? How can I make this
work? Would appreciate if someone can guide me as I am a python
newbie... :-)

Thanks very much...

##In Python
def setAddOnValue(oBusObj
    oAddOns = oBusObj.AddOns
    print oAddOns #returns "<COMObject <unknown>>" 
    print oAddOns.Count #return 3
    for x in range(1, oAddOns.Count):
        oAddOn = oAddOns.Item(x) #expects variant datatype for the x

##In VB
Public Function setAddOnValue(oBusObj As Variant, strAddOnLabel As
String, strPropLabel As String, oVal As Variant) As Boolean
    Dim x, y
    Dim oAddOns As CAddOns
    Dim oAddOn As CAddOn
    Dim oAddOnValues As CAddOnValues
    Dim oAddOnValue As CAddOnValue
    setAddOnValue = False
    Set oAddOns = oBusObj.AddOns
    For x = 1 To oAddOns.Count
        Set oAddOn = oAddOns.Item(x)
        If oAddOn.AddOnName = strAddOnLabel Then
            Set oAddOnValues = oAddOn.AddOnValues
            For y = 1 To oAddOnValues.Count
                Set oAddOnValue = oAddOnValues.Item(y)
                If oAddOnValue.PropertyLabel = strPropLabel Then
                    setAddOnValue = True
                    Set oAddOnValue.Data = oVal
                    Exit For
                End If
            Next y
        End If
        If setAddOnValue = True Then
            Exit For
        End If
    Next x
End Function

More information about the Python-list mailing list