<br><br><div class="gmail_quote">On 19 November 2010 00:20, Joel Schwartz <span dir="ltr">&lt;<a href="mailto:joel@joelschwartz.com">joel@joelschwartz.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">




<div><div dir="ltr" align="left"><font color="#0000ff" size="2" face="Arial"><span>For those of us who are new to writing code that makes 
various software packages interact with each other, can you say more about what 
&quot;COM object model&quot; means in this context and where one can learn how to use it 
to make Python interact with Excel and with Windows software in general. I&#39;ve 
seen term &quot;COM&quot; before and I know it has something to do with how Windows 
programs interact with each other, but that&#39;s about it. Can you suggest some 
resources for learning more?</span></font><br></div></div></blockquote></div><br>Sure, I&#39;ll just add to what Alan and Emile&#39;s already said. <br><br>The first thing (that&#39;s perhaps obvious but I&#39;ll just mention it explicitly) about COM is that it was one of the earlier attempts at solving the programming language and application interoperability problem.  E.g, how do we write code so that other languages can easily consume our functionality, and vice versa?  DDE was an early attempt by Microsoft at a solution, and COM was an attempt by Microsoft&#39;s at a more comprehensive and general answer to this.  It basically defines a set of standards and API&#39;s that effectively can serve as a language-agnostic bridge between different programming languages, if those languages are &quot;COM enabled&quot; by their supporting and complying with COM&#39;s requirements.  <br>
<br>An important extension or evolution of COM to networks was called DCOM (or &quot;Distributed Component Object Model&quot;.)  As the name aludes, it extends COM so that it can operate accross a network.  In other words, have a program on one computer instantiate a component or object (possibly implemented in another language) on another computer, and work with this object as if it&#39;s a local object part of the lcoal program.   Depending on how well a language supports and is integrated with COM/DCOM this may and should for the most part even look like a local native object in the language being programmed in.  <br>
<br>DCOM eventually was further evolved into and eventually included under the moniker of COM itself, and a set of extensions to DCOM that solved/addressed a bunch of additional problems/concerns (like security and object pooling, that you would have to deal with yourself when using only COM/DCOM that typically occurs in the context of distributed applications) was then called COM+.   (For more see <a href="http://ur.ly/v1Xy">http://ur.ly/v1Xy</a> and <a href="http://ur.ly/v8Ii">http://ur.ly/v8Ii</a>)  <br>
<br>Anyway, suffice it to say, COM and friends introduces its own set of downsides and issues (suffice it to say I&#39;ve lost a not insignificant amount of blood fighting with obscure DCOM security issues in the past), which eventually was at least one of the reasons for Microsoft eventually coming up with the .Net framework.  (.Net then, is at one level another attempt at solving the language interoperability problem in a more seamless and elegant way.  WSDL and web services standards were another, targetting the program interoperability accross the web/internet at large, COM/DCOM originally targetted local area networks and doesn&#39;t work very well or easily accross the internet.)<br>
<br>As for resources, there&#39;s a seemingly decent presentation on Python and COM and friends here: <a href="http://ur.ly/voQt">http://ur.ly/voQt</a><br><br>Also there&#39;s Activestate&#39;s documentation that&#39;s appropriate: <br>
<a href="http://docs.activestate.com/activepython/2.5/pywin32/html/com/win32com/HTML/GeneratedSupport.html">http://docs.activestate.com/activepython/2.5/pywin32/html/com/win32com/HTML/GeneratedSupport.html</a><br><a href="http://docs.activestate.com/activepython/2.5/pywin32/html/com/win32com/HTML/QuickStartClientCom.html">http://docs.activestate.com/activepython/2.5/pywin32/html/com/win32com/HTML/QuickStartClientCom.html</a><br>
<br>The package that enables Python to interoperate with COM applications/languages (as well as making available much of the Windows Win32 API&#39;s as well as the &quot;PythonWin&quot; application) is called &quot;pywin32&quot; and is available here:<br>
<a href="http://sourceforge.net/projects/pywin32/">http://sourceforge.net/projects/pywin32/</a><br><br>While the Python package &quot;win32com&quot; which is included in pywin32 (which enables Python to interoperate with COM applications/languages) provides a number of ways of querying and
accessing COM interfaces with few obvious differences between them (provided
you know the interface), it is usually more convenient when experimenting to know
what methods and properties are really available for a given interface as well as being more efficient to use so called &quot;early-binding&quot; when accessing COM objects. This
is where the &quot;makepy&quot; utility comes in. By selecting a particular type library and building the
Python wrappers using this tool in advance, more information becomes available since you and Python can then refer to the generated Python wrappers for casual investigation of object interfaces.  All of this is also covered above in the ActiveState documentation as well as here: <a href="http://oreilly.com/catalog/pythonwin32/chapter/ch12.html">http://oreilly.com/catalog/pythonwin32/chapter/ch12.html</a><br>
<br>Hopefully that clarifies things a bit. I would suggest you try install the pywin32 package, then have a go at playing around with Excel perhaps interactively at first, and then with the tools and examples as outlined in some of the links I&#39;ve posted.  (As an aside, obviously I&#39;ve commented mostly only on using Python as a COM client, it is also possible to write COM servers in Python, e.g. making your Python program available to other COM enabled programs and languages.  Emile&#39;s post is relevant to this topic.  )<br>
<br>HTH, <br><br>Walter<br>