[python-win32] COM, Acrobat and JavaScript

Mark Hammond mhammond@skippinet.com.au
Thu, 7 Mar 2002 14:47:54 +1100

> -- from dynamic.py
> # These errors generally mean the property or method exists,
> # but can't be used in this context - eg, property instead of a
> method, etc.
> # Used to determine if we have a real error or not.
> -- end
> Sorry, I guess I should read the comment before I post.
> So if one of these errors occurs during a dynamic attribute lookup, is
> there some sort of secondary lookup that is tried?

Yes - it is looked up as a method.

We could ignore all errors - but that would mask other real errors.


   a = foo.bar

If fetching this value raises an exception, then almost certainly we want
that exception to be raised as the line above is executed.

However, if the exception is really just telling us "hey - you can't fetch a
property of that name, but there may actually be a method you can call of
that name", then we need to allow it to be used as a method.


   a = foo.bar()

Looks identical to the former without the parens from the POV of the
__getattr__ function.

So - the key to solving this is to force makepy to work somehow.  It appears
this object is similar to Lotus Notes - ie, there is a type library, but
anonymous COM objects don't tell COM they are described in the type library.
Our book describes how to force makepy generated objects to be used, or
search deja for references to Lotus Notes, but basically you use something

mod = gencache.EnsureModule(blah)

# instead of
# ob = Dispatch("WhateverItIs")
ob = mod.Whatever()

Properties and methods should then work perfectly.