0

I am using python2.7 with win32com module to access a win32 COM Library. with:

import win32com.client
app = win32com.client.Dispatch('Word.Application')

I get an application object that works fine in python, although I do have only late binding available.

Now I would like to inherite from this class:

class icad(app):
    pass

whicht throws the following exception:

TypeError: Error when calling the metaclass bases
__init__() takes at most 2 arguments (4 given)

Is there a way to inherit from these COM classes at runtime? Metaclass seems to be the hint but I do not know where to start.

Johannes Maria Frank
  • 2,747
  • 1
  • 29
  • 38
  • 3
    `win32com.client.Dispatch` returns an instance, not a class, so subclassing it doesn't make any sense. What exactly are you hoping for your "subclass" to do? – Wooble Sep 04 '12 at 16:51
  • I use Intellicad and would like to have one object for each drawing. In order not to rewrite each class by myself I would like to inherit form the already existing structure. I think I'll try to use the instances to fill in my own properties. Nevertheless can't I derive a class from an object? – Johannes Maria Frank Sep 05 '12 at 08:48
  • Well, you may be able to get `app`'s class and subclass that, but I doubt your instances of it will actually be connected to the `Word.Application` library. Why not call `win32com.client.Dispatch` in your `__init__` method of a regular class and not try to subclass anything at all? – Wooble Sep 05 '12 at 11:35
  • Thank you, I tried this, and it worked in some limiting way. But in the meantime I found out, I can get the class with: win32com.client.gencache.GetClassForProgID('Icad.Application') I can inherit from this as long as I stick to old class style, which I can live with. – Johannes Maria Frank Sep 07 '12 at 09:45

0 Answers0