Thomas Heller schrieb: > To access a property with optional parameters, we have to use indexing > with NO parameters. Unfortunately, this is not valid Python syntax: > > ...Range["A1:B1"].Value[] > > but this is (it will pass an empty tuple to the __getitem__ method): > > ...Range["A1:B1"].Value[()] > > Indeed, the test_excel.py unittests work when we change the code accordingly.
Sorry for the misinformation: the test does NOT work with the comtypes 0.4.0 code and the above changes. This small patch is required so that the comtypes property setters accept multi parameters: Index: comtypes/__init__.py =================================================================== --- comtypes/__init__.py (revision 58899) +++ comtypes/__init__.py (working copy) @@ -603,7 +603,11 @@ def __setitem__(self, index, value): if self.setter is None: raise TypeError("object does not support item assignment") - self.setter(self.im_inst, index, value) + if isinstance(index, (list, tuple)): + args = tuple(index) + (value,) + self.setter(self.im_inst, *args) + else: + self.setter(self.im_inst, index, value) class named_property(object): def __init__(self, fget=None, fset=None, doc=None): > The following code has the same effect, because apparently passing > 'xlRangeValueDefault' > is the same as passing nothing: > > ...Range["A1:B1"].Value[xlRangeValueDefault] > > If we can live with the above, fine. If not, ONE possibility that I see > would be that comtypes creates additional setter and getter functions for the > 'Value' property, maybe called _setValue(...) and _getValue(...). Well, getting the property by calling the 'Value' works: ...Range["A1:B2].Value() This functionality was probably implemented by taking win32com as example, but I am no longer sure that I like it. But it will probably stay for compatibility. Thomas ------------------------------------------------------------------------- This SF.net email is sponsored by: Splunk Inc. Still grepping through log files to find problems? Stop. Now Search log events and configuration files using AJAX and a browser. Download your FREE copy of Splunk now >> http://get.splunk.com/ _______________________________________________ comtypes-users mailing list comtypes-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/comtypes-users