Re:  Problem registering Python COM object (suddenly)

Hi,

I've been volunteering for the Research Dept. of Selby Botanical Gardens
here in Sarasota, FL.  In support of my project I wrote a Python COM server
to extend Python's regular expression capabilities to VB.  (I'm aware of VB
regular expression support, which doesn't include look-behinds.)

The computer I use at the Gardens has XP SP2 and Access 2003.  Two or three
weeks ago I installed Pywin32 (Active State) at the Gardens by downloading
the latest version of 2.5 (build 211?).  At home I run Active State 2.5
211.1.

I believe the software is up-to-date.  When I originally installed my Python
COM object, the Access application ran flawlessly.  However, after a week's
absence, I can't even seem to register the COM object (which has changed).  

The symptoms occur during a query that computes a value using the COM
object.  I get the Access message "Error ??? the object doesn't support that
method".  If I stop the query with a break point in VB, I can see that my
object exists (probably from the DIM statement).  However, it doesn't seem
to be associated with the Python COM object.

Everything works swimmingly at my development computer.  Between last week's
visit and today's visit, things won't work at the Gardens.

The computer there is very low on C: disk space.  Could this have an effect
on win32com's registration of the COM object?

Is there a method for positive validation that the object is registered?
The Tools.References menu item doesn't help, and at my development computer
it doesn't show up as an ActiveX component, although it is obviously
registered and accessible to VB.  Also Application.COMAddins.Item() doesn't
show it on either machine.  This is puzzling.

I've run out of leads.  Any clues, anyone?  The code follows, although I
don't believe it is the code, but rather some external condition of which
I'm unaware.

Here is the Python code:

 

class reObj:

       import pythoncom

       import re

       import string

      _public_methods_ =
["allMatches","substitute","replaceAll","occurs","listem"]

       _reg_progid_ = "Python.reObj"

       _reg_clsid_ = pythoncom.CreateGuid()

       def __init__ (self):

             pass

       def allMatches(self, pattern, str):

             import re

             import string

             result=''

             matchGroup=re.search(pattern,str)

             while matchGroup<>None:

                    (start,end)=matchGroup.span()

                    result = result + ", " + str[start:end]

                    str=str.replace(str[start:end],'',1)

                    matchGroup=re.search(pattern,str)

             return result[2:]

       def substitute(self,str,pattern,replacement,count=1):

             str=str.replace(pattern,replacement,count)

             return str

       def replaceAll(self,str,pattern,replacement):

             str=str.replace(pattern,replacement)

             return str

       def occurs(self,str,pattern):

             result=''

             matchGroup=re.search(pattern,str)

             count=0

             while matchGroup<>None:

                    count=count+1

                    (start,end)=matchGroup.span()

                    str=str.replace(str[start:end],'',1)

                    matchGroup=re.search(pattern,str)

             return (count)

 

if __name__ == '__main__':

       import win32com.server.register

       win32com.server.register.UseCommandLine(reObj)

And here is the VB code that calls it:

 

Public Function fLatitude(str As String) As String

    Dim degreesPattern As String

    Dim minutesPattern As String

    Dim secondsPattern As String

    Dim degrees As String

    Dim minutes As String

    Dim seconds As String

    Dim s As String

    Dim ns As String

    Dim r As Object

    Set r = CreateObject("Python.reObj")

    degreesPattern = "(\d+(\.\d+)?...@])"

    minutesPattern = "(\s?\d+(\.\d+)?[!])"

    secondsPattern = "(\s?\d+(\.\d+)?[=])"

    latitudePattern = "(\d+(\.\d+)?...@!=]\s?)+[NS](?=[\s\.,;]|$)"

    agn = fAgnosticLatLong(str)

    s = r.allMatches(latitudePattern, agn)

    If Len(s) = 0 Then

        fLatitude = ""

        Exit Function

    End If

    ns = Right(s, 1)

    degrees = r.allMatches(degreesPattern, s)

    minutes = r.allMatches(minutesPattern, s)

    seconds = r.allMatches(secondsPattern, s)

    degrees = r.replaceAll(degrees, "@", "*")

    minutes = r.replaceAll(minutes, "!", "'")

    seconds = r.replaceAll(seconds, "=", """")

    fLatitude = degrees & minutes & seconds & ns

    Set r = Nothing

End Function

 

Works perfectly at home, but not at all (now) at the pro-bono client.

If you've read this far, my deepest thanks, 

Cheers, Gary

___________________________________

"Even for practical purposes theory generally turns out the most important
thing in the end."  Oliver Wendell Holmes.

 

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

Reply via email to