Python and COM: a bug?

Gaetan Corneau Gaetan_Corneau at
Wed Nov 24 09:18:35 EST 1999


> Well if you can reproduce it, others will try to fix it!

Thats the problem: it is very difficult to reproduce.

> Or at least try to find a workaround, if it can't be fixed. 

I already have a workaround. Maybe you didn't see my original message.

> Just sitting around saying this or that sometimes happens doesn't help 
> many people out.

Of course I know that. The point was just to ask other Python users if they
had ever experienced this strange problem. It seems most Python COM users
(which, I suppose, are a small subset of the Python community) don't.

> Saying your C++ code is ok just because it works with 
> VB/VBScript doesn't necessarily make it ok code. 

I know. I'm not new to programming, you know :)
But I really think that the C++ code is OK. It works when called from
VBScript, C++ and Delphi. Those components have been tested intensively and
is currently being tested by over 20 people.

I have received too much help from Mark Hammond to bad mouth his work: I'm
sorry if anyone think this is what I'm doing.

Here is my original post:


I have encountered a weird problem a few times in the past months. I'm
testing COM server (written here) with Python, and it seems that there is
something wrong in the code that optimizes the calls to COM objects.
Sometimes (a very rare occurence) the wrong function gets called when I
access a property. Suppose I have object O with properties a (an int), b (a
date), c (a string), then

print O.b

would give me 
"Hello, world"

The error always seem to be off by one (in the same direction), but I'm not
absolutely sure about that.

And sometimes, I get something like that:

>>> Object
<COMObject <unknown>>
>>> P = Object.Parent # Parent is an attribute that is the object that
created the current object
>>> P
<method CDispatch.Parent of CDispatch instance at c5e780>
>>> P = Object.get_Parent()
>>> P
<COMObject <unknown>>

I didn't talk about those problems 'til now because they're very hard to
reproduce and describe. And I can't just send the components to a volunteer
who would try to find the problem, because he would need to install 417 Mb
of our software to recreate the environment :(

I have workarounds, but what really annoys me is that I'm still fighting a
couple of guys here to get Python accepted: they always ask "why don't you
just use VBScript?", and it's true that I don't have those problems with
VBScript (because VBScript doesn't try to optimize calls).

I'll try to find what the problem is by tracing the Python code, but since
I'm not familiar with it, I don't expect to find the cause. At this point,
all I want to know is if I'm the only one with that kind of strange


   Gaetan Corneau
   Software Developer (Quality Assurance Team)
   BaaN  Supply Chain Solutions
   E-mail: Gaetan_Corneau at                  
   Tel: (418) 266-8252          
"Profanity is the one language all programmers know best"

More information about the Python-list mailing list