instance of COM-server with Win32all

Mark Hammond mhammond at skippinet.com.au
Mon Nov 24 22:42:45 CET 2003


Michel Claveau/Hamster wrote:
> Hi !
> 
> I seek how to define a COM-server in "mono-instance". Do you know if there
> are policies for that ?
> I sought much, but did not find anything.  And i had difficult with english.
> 
> Python is great, Win32all is brilliant, but i am wedged in a corner.
> 
> 
> * and sorry for my bad english * Babelfish was a great help *

I think you are asking how to create a "singleton" using win32com.  The 
simplest way is to *pretend* you have created one.

Consider an object setup like this:

class RealObject:
   def foo(self)...
   def bar(self)...

realObject = RealObject()

class COMOBject:
   _public_methods_ = "foo", "bar"
   def foo(self):
     realOBject.foo()
   def bar(self):
     realObject.bar()

In this case, it doesn't matter how many "COMObject" objects are alive, 
as they will always delegate to the single "RealObject".

If you want a true singleton, you will need to dig a little deeper into 
win32com, and create your own "policy".

Mark.






More information about the Python-list mailing list