468,107 Members | 1,278 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,107 developers. It's quick & easy.

MS COM early and late binding

Is there a way to find out if I am using early or late binding given
the reference ("excel" in the example below) returned by Dispatch()?
import win32com.client
excel = win32com.client.Dispatch('Excel.Application')


Thanks much for your help.

Olaf
Jul 18 '05 #1
4 2875
Ol********@compuserve.com (Olaf Meding) writes:
Is there a way to find out if I am using early or late binding given
the reference ("excel" in the example below) returned by Dispatch()?
import win32com.client
excel = win32com.client.Dispatch('Excel.Application')


try:
excel.visible
except AttributeError:
print "late bound"
else:
print "early bound"

Hint: Attributes are case sensitive when early bound ;-)

Thomas
Jul 18 '05 #2
Thomas

What you suggest might work, but does not look to elegant. Can anyone else
perhaps suggest a more elegant solution? Thanks.

Olaf
try:
excel.visible
except AttributeError:
print "late bound"
else:
print "early bound"

Hint: Attributes are case sensitive when early bound ;-)

Jul 18 '05 #3
Olaf Meding wrote:
Is there a way to find out if I am using early or late binding given
the reference ("excel" in the example below) returned by Dispatch()?

import win32com.client
excel = win32com.client.Dispatch('Excel.Application')


There is no great way to find out (other than looking at the repr() of
the object or trying Thomas's trick), but there is a way to force one or
the other.

excel = win32com.client.gencache.EnsureDispatch(excel)

Will ensure you have early bound, executing makepy if necessary.

excel = win32com.client.dynamic.DumbDispatch(excel)

Will force late bound, even if the object is currently early.

Mark.
Jul 18 '05 #4
"Olaf Meding" <Ol********@noSpam.compuserve.com> wrote in message news:<40**********@newspeer2.tds.net>...
What you suggest might work, but does not look to elegant. Can anyone else
perhaps suggest a more elegant solution? Thanks.


Not elegant? This is COM, you know!

Anyway, I do this:

excel = win32com.client.gencache.EnsureDispatch('Excel.App lication')

Then I know I'm using early binding.

Cheers,
Simon B.
Jul 18 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Mystery Man | last post: by
reply views Thread by RN1 | last post: by
1 post views Thread by pedestrian via DotNetMonster.com | last post: by
1 post views Thread by Solo | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.