How to pass true or false to COM objects?

Duncan Booth duncan at
Mon Aug 19 10:53:54 CEST 2002

sjoshi at (Sunit Joshi) wrote in 
news:8f8ffe67.0208161214.4a39ce42 at

> I'm using MSXML4.0 and need to pass 'true' or 'false' values to the
> COM object. Could someone tell me how to do that..??

If my memory serves (and it might not), then passing True or False as 
values will work providing you are using Python 2.2.1 or later. In earlier 
versions you should make sure you pass in the result of a comparison: e.g. 
   True, False = 1==1, 1==0
somewhere in your code and you now have suitable values to pass in.

The explanation for this weirdness is that normally Python optimises any 
expression involving small integers by reusing the same objects for these 
integers (so for example '(7+3) is (1000/100)' is true. The exception to 
this rule is that comparisons use their own 0 and 1 objects (e.g. '1 is 
3>2' has the value 0). The COM system makes use of this fact to guess 
whether it should pass an integer or a boolean outside Python.

As of 2.2.1 new builtins True and False were added which expose the boolean 
1 and 0 objects. In a future version they may become a separate boolean 
type (subclassing int).

Duncan Booth                                             duncan at
int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3"
"\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure?

More information about the Python-list mailing list