Novice question: Implementing COM Objects with Python

Rolfe rolfedh at hotmail.com
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\scriptutils.py",
line 301, in RunScript
    exec codeObject in __main__.__dict__
  File "C:\Python22\examples\SimpleCOMServer.py", line 4, in ?
    class PythonUtilities:
  File "C:\Python22\examples\SimpleCOMServer.py", line 8, in
PythonUtilities
    print pythoncom.CreateGuid()
NameError: name 'pythoncom' is not defined
>>> 
"

What am I doing wrong? 

Code:
"
##SimpleCOMServer.py - 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
    win32com.server.register.UseCommandLine(PythonUtilities)
"




More information about the Python-list mailing list