MS COM early and late binding

O

Olaf Meding

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()?

Thanks much for your help.

Olaf
 
T

Thomas Heller

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()?

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

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

Thomas
 
O

Olaf Meding

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 ;-)
 
M

Mark Hammond

Olaf said:
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()?

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.
 
S

Simon Brunning

Olaf Meding said:
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.Application')

Then I know I'm using early binding.

Cheers,
Simon B.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top