How does one set a value via win32com

Alex Martelli aleaxit at yahoo.com
Wed Mar 28 11:16:01 EST 2001


"Stefan Migowsky" <smigowsky at dspace.de> wrote in message
news:mailman.985764036.26774.python-list at python.org...

"""
you ran on a problem with dynamic dispatch. It can't use properties
with parameters. In a makepy generated wrapper properties with parameters
are translated in methods. So you must use a wrapper to use such parameters.
To ensure a wrapper use the gencache module, in your case
"""

Yes, but... that's what I thought I'd advise, too, but then I
tried out a simple (?) case and just can't make it work.  I.e.:

D:\Python20\Lib>python
Python 2.0 (#8, Oct 16 2000, 17:27:58) [MSC 32 bit (Intel)] on win32
Type "copyright", "credits" or "license" for more information.
>>> from win32com.client.gencache import EnsureDispatch as disp
>>> dic=disp("Scripting.Dictionary")
>>> dic
<win32com.gen_py.Microsoft Scripting Runtime.IDictionary>
>>> dic.Item("foo","bar")
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
TypeError: too many arguments; expected 2, got 3
>>>

So how does one do the Python equivalent of VBS's
    dic.Item("foo")="bar"
i.e., set an indexed property?  Scripting.Dictionary
is nice in ALSO making a method (SetItem) available
duplicating the indexed-property put, but not all
COM objects with indexed properties will be as nice
as that -- how do I put the indexed property directly
then?  I thought I knew, but, it turns out I was wrong,
and I'm now wondering how (or whether) it's done...


Alex






More information about the Python-list mailing list