[python-win32] Possible bug: what information to provide

Mark Hammond mhammond at skippinet.com.au
Thu Oct 13 06:00:38 CEST 2005


> > > One more strange thing:
> > > MakePy recognised the object as "IRepository" rather then "Repository"
> >
> > I'm not sure what you mean here.  Please post a complete code sample,
> > including all output that confuses you or you believe to be wrong.
> >
> Makepy.py output (fragment, for information about the Object)
> -----------------------------------------------
> class IRepository(DispatchBaseClass):

Right - that is normal.  It is indeed the interface that has the method -
the "coclass" described in the file probably has a reference to that
interface - a coclass may implement many interfaces.

> > The code above is not using makepy, even though it may have
> > been run.  You
> > could try creating the object using
> > win32com.client.gencache.EnsureDispatch
>
> I tried, here is the result:
> -----------------------------------
> >>> rep = win32com.client.gencache.EnsureDispatch('EA.Repository')
> Traceback (most recent call last):
>   File "<interactive input>", line 1, in ?
>   File "C:\Python24\Lib\site-packages\win32com\client\gencache.py", line
> 543, in EnsureDispatch
>     raise TypeError, "This COM object can not automate the makepy
> process -
> please run makepy manually for this object"
> TypeError: This COM object can not automate the makepy process -
> please run
> makepy manually for this object

Sadly, this object is not providing its typeinfo at runtime.  If you can get
in touch with the developers, ask them to consider adding this IDispatch
typeinfo support - they already have the typeinfo available from their
typelib, so it should be quite easy to do.

In the meantime, you need to explicitly "cast" your objects into these
makepy objects.  You should start by running "makepy.py -i" (from a
command-prompt).  Here is what I get when I pick some random lib:

 IAS Helper COM Component 1.0 Type Library
 {6BC096BB-0CE6-11D1-BAAE-00C04FC2E20D}, lcid=0, major=1, minor=0
 >>> # Use these commands in Python code to auto generate .py support
 >>> from win32com.client import gencache
 >>> gencache.EnsureModule('{6BC096BB-0CE6-11D1-BAAE-00C04FC2E20D}', 0, 1,
0)

You should add these lines to your code - but with one change:

> from win32com.client import gencache
> mod = gencache.EnsureModule('{6BC096BB-0CE6-11D1-BAAE-00C04FC2E20D}', 0,
1, 0)

Note the last line - 'mod ='.  This will be the makepy module, as imported
from the gen_py directory.  You can then write:

rep = win32com.client.Dispatch('EA.Repository')
# Now 'cast' it to an IRepository object.
rep = mod.IRepository(rep)

print repr(rep) # Should now print a repr that indicates it is a makepy
object.

You will need to this whenever you get a "new" object.  Eg, let's say there
was a "GetApplication()" method on a repository.

app = rep.GetApplication()
print repr(app) # will probably say "<COM object ...>" - not what you want.
app = mod.IApplication(app) # Cast to a mythical IApplication object.
print repr(app) # should show the makepy object.

Hope that makes sense,

Mark



More information about the Python-win32 mailing list