Win32 COM

Tom Plunket tomas at fancy.org
Wed Nov 1 19:38:02 EST 2006


I don't know anything about COM beyond the fact that I can look in the
OLE/COM browser to maybe figure out the API that an object has that I
need to operate on.  Usually this gets me by fine; I've written mostly
utilities for Developer Studio which work fine if a little slow, and a
bit of junk for some other bits of the MS Office suite.  However, now
I'm a bit stuck.

I've got this object, and the documentation and sample code imply that
I can just call this method I need to call on it, and ding-dong.  It's
for creating a "command" object to pass to the application, and it
works (or rather, is supposed to work) sorta like this:

  operation = win32com.client.Dispatch('AppHelper.AppParameter')
  operation.Command = 'A_Command_Name'
  operation.SetParameter('param1', 'value')

However, I get an attribute error on the SetParameter call, which
indicates that it doesn't exist.

So, I look at the object browser, and sure enough it isn't there.
However, there is a 'Parameter' method.  Oh wait, there are two.
There's one that takes the parameter name and (presumably) returns the
value, and there's another that takes the parameter name and the value
that it's set to.

Through fiddling with this thing in IPython, I found that I can do:

  operation.Parameter('foo')

...which throws an exception, but once that's been run, I can do what
I set out to do:

  operation.SetParameter('param1', 'value')

...and all is well.

Can anyone give me any tips as to what's going on here and what I
might be doing wrong?  I have /not/ run the makepy.py or whatever it
is, since when I roll this out to the team I don't want to have to run
that on every machine before it'll work, but if that's what I need to
do, well, so be it.  However, at this time I'm stumped as to what to
try except that I can have a dirty-feeling try/except bit to "enable"
that call...

thx,
-tom!



More information about the Python-list mailing list