Python COM object: attribute value typing
Mark Hammond
mhammond at skippinet.com.au
Wed Jan 23 19:38:54 EST 2002
Steve Holden wrote:
> Quite an odd one, this. I'm creating a COM object in Python and accessing it
> from VBscript. I set a value true/false with the following statement in the
> COM object:
>
> self.AVS_aok = (r in "23")
>
> AVS_aok is to be found in both _public_attrs_ and _readonly_attrs_, if it
> matters. When I access this attribute from VBscript it comes back with
> TypeName "Boolean", and values True/False, where I would have expected a
> simple 1 or 0.
>
> I would not have though that Python retained anything other than the 0 or 1
> result. How can this be?
Python has internal PyTrue and PyFalse objects. boolean expressions
will return one of these objects, rather than the simple 1 and 0
objects. Even though they are both integers, PythonCOM can still make
the distinction.
ie:
>>> true=(1==1)
>>> true==1
1
>>> true is 1
0
>>>
PythonCOM explicitly creates a VT_BOOL variant when it sees either
PyTrue or PyFalse.
Mark.
More information about the Python-list
mailing list