Differences Between Early and Late Binding
There are a number of differences between using early and late binding within Python. All these changes are specific to Python and not to COM itself. These differences are most significant when moving from code that uses late binding to code that uses early binding.
The key difference is the handling of parameters; in fact, these differences are so significant that we discuss them separately later in the section Passing and Obtaining Python Objects from COM.
Another fundamental difference is case sensitivity. Late
binding is generally not sensitive to the case of methods and
properties, while early binding is. To see an example of this, create
a late-bound Excel object and adjust its
Visible
property. As discussed in the previous
section, you force a late-bound object even if MakePy support exists
for the object:
>>> import win32com.client.dynamic
>>> xl=win32com.client.dynamic.Dispatch("Excel.Application")
>>> xl.Visible=1
>>> print xl.VISIBLE
1
>>>You can use both Visible and
VISIBLE
in this context.
Now let’s try the same example using early bindings. Assume that you have generated MakePy support for Microsoft Excel and use the same code:
>>> import win32com.client >>> xl=win32com.client.Dispatch("Excel.Application") >>> xl.Visible=1 >>> print xl.VISIBLE Traceback (innermost last): File "<stdin>", line 1, in ? File "c:\Program Files\Python\win32com\gen_py\00020813-0000-0000-C000- 000000000046x0x1x2.py", line 1462, in __getattr__ raise ...Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access