'How can I set the value of an indexed property of a COM object in Python?

I have come to a point where one of the properties that I must change (i.e. set) is an indexed get/set property of an object. I am controlling an application through its COM interface. The different objects of the application provide access to properties, methods and events. I am stuck..

What I want to do in Python, looks like this in C#:

GeneralSetup.Channels[eBusType.cLIN]++;

where:

  • GeneralSetup: Object of class GeneralSetup
  • Channels[eBusType]: Property in GeneralSetup (int Channels {get; set;})
  • eBusType: Enumerator with values indicating a bus type

In Python (3.9.7) I can get the value of the indexed property Channels, but I cannot set a new value of the property, see the example below:

channel_usage = GeneralSetup.Channels(eBusType.cLIN) # This works
GeneralSetup.Channels(eBusType.cLIN) = channel_usage + 1 # Error: Cannot assign to a function call


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source