[python-win32] win32com and static dispatch

Michael Thompson spamtrap at day8.com.au
Wed Nov 2 23:35:42 CET 2005


Michael Thompson wrote:
> 
> Great. So dynamic dispatch works just fine.  Except, of course, I can't 
> get the 'constants' and its a bit inefficient, so I tried switching to 
> static dispatch:
> 
>       >>> dispatch = win32com.client.gencache.EnsureDispatch
>       >>> xlApp = dispatch('Excel.Application')
>       >>> books = xlApp.Workbooks.Open('SomeNew.xls')
> 
> But now, when I look at 'books':
> 
>      >>> books
>      <win32com.gen_py.None.Workbook>
> 
> which seems to mean 'books' is unusable:
> 
>      >>> books.WorkSheets('channels')
>      Traceback (most recent call last):
>      ...
>      AttributeError: '<win32com.gen_py.Microsoft Excel 11.0 Object 
> Library._Workbook instance at 0x13234048>' object has no attribute 
> 'WorkSheets'
> 

I've found the problem. Groan.  Dynamic and Static dispatch differ WRT to case sensitivity.

My tests involved this:

      >>> books.WorkSheets('channels')

You'll see that I'm incorrectly using CamelCase for 'Worksheets'.  Using Dynamic dispatch I got away with this "case" error, but not with static dispatch.

--
Mike



More information about the Python-win32 mailing list