Novice question: Implementing COM Objects with Python

Uwe Schmitt uwe.schmitt at
Tue Jan 28 23:24:32 CET 2003

Rolfe <rolfedh at> wrote:
> I'm trying the code (see further down) from Mark Hammonds Python
> Programming on Win32, page 68, and get the following error:
> ...
> What am I doing wrong? 

It looks like missing "import pythocom (from....)" ...

You should uncomment the "_reg_clsid_.." line,
generate the GUID once, 
( type 'import pyhtoncom' and 'print str(pythoncom.CreateGuid())'
  at the python command line)
and insert it in the code.

As far as I understand your code, you will get different
GUID's with each invokation, which makes no sense.

The 'print' makes no sense in the class definition.

Greetings, Uwe.

> Code:
> "
> - a sample com server
> ##
> ##we expose a single method in a python com object
> class PythonUtilities:
>     _public_methods_ = [ 'SplitString' ]
>     _reg_progid_ = "PythonDemos.Utilities"
>     #NEVER copy the following ID
>     print pythoncom.CreateGuid()
>     #_reg_clsid_ = print.pythoncom.CreateGuid()

>     def SplitString(self, val, item=None):
>         import string
>         if item != None: item = str(item)
>         return string.split(str(val), item)

Dr. rer. nat. Uwe Schmitt      Computer science is no more about Computers,
uwe.schmitt at      than astronomy is about telescopes. (Dijkstra)           

More information about the Python-list mailing list