[python-win32] Dynamic dispatching and AttributeErrors,

Mark Hammond skippy.hammond at gmail.com
Thu Nov 18 07:19:56 CET 2010


On 16/11/2010 5:14 AM, Brian Merrell wrote:
> I am using Windows 7, 32-bit python 2.6, 2.7 and the latest win32 release.
>
>     * makepy seems to work, I find what appears to be the one and only
>       appropriate library and it places an early binding skeleton file
>       in the expected gen_py directory.  Anticipated classes and methods
>       are observed.
>     * Whenever I call win32com.client.Dispatch on the "common name" (as
>       derived from the skeleton file) it seems to return the dynamic
>       dispatched version (even after using the EnsureModule method)

The above can happen for some objects which don't correctly report their 
type information at runtime - in which case you can often trick things 
using code similar to:

mod = win32com.gencache.EnsureModule(...)
ob = win32com.client.Dispatch(...)
# convert from dynamic to makepy supported.
ob = mod.GeneratedClassName(ob)


>     * When I try calling a known method on the returned COM object I get
>       an AttributeError
>     * I've also tried using every CLSID I can find in my skeleton file c
>       = Dispatch(CLSID) which results in either a "Class not registered"
>       or an object that also gives an AttributeError for a known method.

A traceback would be useful here - if the object really is a dynamic 
object, an AttributeError implies that the object itself also doesn't 
think the attribute exists (as dynamic objects ask the object for the 
attribute before raising an AttributeError).

HTH,

Mark


More information about the python-win32 mailing list