Novice question: Implementing COM Objects with Python

Rolfe rolfedh at
Tue Jan 28 23:15:46 CET 2003

I'm trying the code (see further down) from Mark Hammonds Python
Programming on Win32, page 68, and get the following error:
"Traceback (most recent call last):
  File "C:\Python22\Lib\site-packages\Pythonwin\pywin\framework\",
line 301, in RunScript
    exec codeObject in __main__.__dict__
  File "C:\Python22\examples\", line 4, in ?
    class PythonUtilities:
  File "C:\Python22\examples\", line 8, in
    print pythoncom.CreateGuid()
NameError: name 'pythoncom' is not defined

What am I doing wrong? 

" - 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)

#add code so that when this script is run by
#python.exe, it self-registers.
if __name__=='__main__':
    print "Registering Com server.."
    import win32com.server.register

More information about the Python-list mailing list