By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,923 Members | 1,279 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,923 IT Pros & Developers. It's quick & easy.

MS COM early and late binding

P: n/a
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
Share this Question
Share on Google+
4 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
"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.