Passing and Obtaining Python Objects from COM
COM supports a variety of argument
types, using the
VARIANT
data structure. The types that
can be passed to COM functions include integers and floats of various
sizes, strings, date/time values, COM objects, or arrays of any of
these types.
In many cases, PythonCOM can translate between Python objects and
VARIANT structures seamlessly. When you call a COM
object and pass a Python object, PythonCOM automatically creates a
VARIANT of the right type and passes the
VARIANT to COM. In the absence of any hints,
PythonCOM performs the translations as listed in Table 12.1 and Table 12.2. In Table 12.1, for example, you can see that a Python
integer is automatically converted to a VARIANT
type VT_I4.
|
Python Object Type |
VARIANT Type |
|
Integer |
|
|
Long Integer |
|
|
String/Unicode |
|
|
Float |
|
|
|
|
|
None |
|
|
|
|
|
|
|
|
All other |
|
|
|
|
|
Any other Python sequence |
An array of VARIANTs; each element of the sequence is translated using this table |
|
VARIANT Type |
Python Object |
|
|
Integer |
|
|
Float |
|
|
|
|
|
|