Hello group,

Following the example in Mark's book, I tried creating a simple COM server
exposing two methods from the re module. But could not get it to work. Here is
the code:

class PythonModule_re:
    _public_methods_ = ['pyfindall', 'pysplit']
    _reg_progid_ = "PythonModule.re"
    # NEVER copy the following ID 
    # Use "print pythoncom.CreateGuid()" to make a new one.
    _reg_clsid_ = "{770E12AD-FED0-47C1-8457-E737FE6F5843}"

    def pyfindall(self, pat, s):
        import re
        return re.findall(re.compile(pat), s)

    def pysplit(self, pat, s):
        import re
        return re.split(re.compile(pat), s)

if __name__=='__main__':
    print "Registering COM server..."
    import win32com.server.register
    win32com.server.register.UseCommandLine(PythonModule_re)

This is the vba code to test the COM server from which I got an error saying
"Objects doesn't support this property or method."

Public Sub Test()
    Dim pyRegex As Object
    Dim r1 As Variant
    Dim r2 As Variant
       
    Set pyRegex = CreateObject("PythonModule.re")
    r1 = pyRegex.pyfindall("\d", "a1b2c3")
    r2 = pyRegex.pysplit("\d", "a1b2c3")
    Debug.Print "Done."
End Sub

The odd thing (to me) was if I rename the function pyfindall to findall, it
works. But I could not do that with pysplit because there is a vb function
called Split.

Any hints? Thanks a lot!

- kelie


_______________________________________________
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32

Reply via email to