COM bites - help please

Karl Putland kperacles at geocities.com
Fri Jul 23 03:32:27 EDT 1999


I've got a couple of pyCOM things that are kicking my @$$! 

1.  Trying to wrap a list of instances into a util.Collection.  All instances have been prepped with _public_methods_ and _public_attrs_ and have been wrapped with a call to win32com.server.util.wrap(field) Trying to access the Collection from a com instance produces the following error.

>>> gm=win32com.client.Dispatch("Python.GMConnector")
>>> c1=gm.GMTable('contact1')
getting table=gmc.GMConnector.GMTable(self, TableName) <gmCOM.GMcomConnector instance at 9373c0> contact1

['lower', 'upper']
Wrapping Table

Looping over fields to set _public_attrs_ for table D:\GOLDMINE\DEMO\CONTACT1.DBF

Wrapping Fields
>>> c1.top()
>>> c1.contact        # This is a GMField instance
<COMObject <unknown>>
>>> c1.contact.read()
'Karn Smith'
>>> c1.fields        # This is a util.Collection(list of GMField instances)
Traceback (innermost last):
  File "<pyshell#56>", line 1, in ?
    c1.fields
  File "D:\Python\win32com\client\dynamic.py", line 394, in __getattr__
    raise pythoncom.com_error, details
com_error: (-2147467259, 'Unspecified error', None, None)


2. A computed attribute in __getattr__ does not want to be accessed through com.  It is in the _public_attrs_  list but produces the following error when attempting to access it.

>>> c1.contact.value
Traceback (innermost last):
  File "<pyshell#55>", line 1, in ?
    c1.contact.value
  File "D:\Python\win32com\client\dynamic.py", line 400, in __getattr__
    raise AttributeError, "%s.%s" % (self._username_, attr)
AttributeError: <unknown>.value

3. PyUnicode objects bit me in the ass when strings are passed into methods and manipulated.
class Foo:
    <COM stuff>
    def bar(self, somestring):
        somestring = string.upper(somestring)
        return somestring

>>>foo = win32com.client.Dispatch("Python.Foo")
>>>foo.bar("Hello World")

Some traceback about TypeError PyUnicode.

Causing a need to change bar to
    def bar(self, somestring):
        somestring=str(somestring)
        somestring = string.upper(somestring)
        return somestring
This change needs to be made in ALL methods that accept and manipulate strings???


Is there a better method than COM for allowing someone who uses VB access to Python objects, short of converting all of the VB users to Python or resorting to reimplementing in VB or C++?  The COM interface I've been able to expose is sufficient for now but does not allow some of the access that I have in Python.  Maybe that's good in the end?

The work I've done in Python is short and sweet.  I hate the thought of having to redo it all Not that the Python stuff would be thrown out,  I just want to release some cool stuff to other GoldMine folks before I am finished with the complete application.

Any help appreciated.

Karl Putland
kperacles at geocities.com






More information about the Python-list mailing list