MS COM early and late binding

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Olaf Meding

    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()?
    [color=blue][color=green][color=darkred]
    >>> import win32com.client
    >>> excel = win32com.client .Dispatch('Exce l.Application')[/color][/color][/color]

    Thanks much for your help.

    Olaf
  • Thomas Heller

    #2
    Re: MS COM early and late binding

    OlafMeding@comp userve.com (Olaf Meding) writes:
    [color=blue]
    > 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()?
    >[color=green][color=darkred]
    >>>> import win32com.client
    >>>> excel = win32com.client .Dispatch('Exce l.Application')[/color][/color]
    >[/color]

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

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

    Thomas


    Comment

    • Olaf Meding

      #3
      Re: MS COM early and late binding

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





      Comment

      • Mark Hammond

        #4
        Re: MS COM early and late binding

        Olaf Meding wrote:
        [color=blue]
        > 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()?
        >
        >[color=green][color=darkred]
        >>>>import win32com.client
        >>>>excel = win32com.client .Dispatch('Exce l.Application')[/color][/color][/color]

        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.Ensur eDispatch(excel )

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

        excel = win32com.client .dynamic.DumbDi spatch(excel)

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

        Mark.

        Comment

        • Simon Brunning

          #5
          Re: MS COM early and late binding

          "Olaf Meding" <OlafMeding@noS pam.compuserve. com> wrote in message news:<408ed8e5$ 1_1@newspeer2.t ds.net>...[color=blue]
          > What you suggest might work, but does not look to elegant. Can anyone else
          > perhaps suggest a more elegant solution? Thanks.[/color]

          Not elegant? This is COM, you know!

          Anyway, I do this:

          excel = win32com.client .gencache.Ensur eDispatch('Exce l.Application')

          Then I know I'm using early binding.

          Cheers,
          Simon B.

          Comment

          Working...