<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=us-ascii">
<META content="MSHTML 6.00.2900.6036" name=GENERATOR></HEAD>
<BODY>
<DIV dir=ltr align=left><FONT face=Arial color=#0000ff size=2><SPAN
class=687383516-19112010>Great information. Thanks to everyone who
replied.</SPAN></FONT></DIV>
<DIV dir=ltr align=left><FONT face=Arial color=#0000ff size=2><SPAN
class=687383516-19112010></SPAN></FONT> </DIV>
<DIV dir=ltr align=left><FONT face=Arial color=#0000ff size=2><SPAN
class=687383516-19112010>Joel</SPAN></FONT></DIV><FONT face=Arial color=#0000ff
size=2></FONT><BR>
<DIV class=OutlookMessageHeader lang=en-us dir=ltr align=left>
<HR tabIndex=-1>
<FONT face=Tahoma size=2><B>From:</B> Walter Prins [mailto:wprins@gmail.com]
<BR><B>Sent:</B> Friday, November 19, 2010 5:52 AM<BR><B>To:</B> Joel
Schwartz<BR><B>Cc:</B> Tutor@python.org<BR><B>Subject:</B> Re: [Tutor] new to
python<BR></FONT><BR></DIV>
<DIV></DIV><BR><BR>
<DIV class=gmail_quote>On 19 November 2010 00:20, Joel Schwartz <SPAN
dir=ltr><<A
href="mailto:joel@joelschwartz.com">joel@joelschwartz.com</A>></SPAN>
wrote:<BR>
<BLOCKQUOTE class=gmail_quote
style="PADDING-LEFT: 1ex; MARGIN: 0pt 0pt 0pt 0.8ex; BORDER-LEFT: rgb(204,204,204) 1px solid">
<DIV>
<DIV dir=ltr align=left><FONT face=Arial color=#0000ff size=2><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 "COM object model" 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've seen term "COM" before
and I know it has something to do with how Windows programs interact with each
other, but that's about it. Can you suggest some resources for learning
more?</SPAN></FONT><BR></DIV></DIV></BLOCKQUOTE></DIV><BR>Sure, I'll just add to
what Alan and Emile's already said. <BR><BR>The first thing (that's perhaps
obvious but I'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's
at a more comprehensive and general answer to this. It basically defines a
set of standards and API's that effectively can serve as a language-agnostic
bridge between different programming languages, if those languages are "COM
enabled" by their supporting and complying with COM's requirements.
<BR><BR>An important extension or evolution of COM to networks was called DCOM
(or "Distributed Component Object Model".) 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'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'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't work very well or easily accross the internet.)<BR><BR>As for resources,
there'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's Activestate's
documentation that'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's as well as the
"PythonWin" application) is called "pywin32" and is available here:<BR><A
href="http://sourceforge.net/projects/pywin32/">http://sourceforge.net/projects/pywin32/</A><BR><BR>While
the Python package "win32com" 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 "early-binding"
when accessing COM objects. This is where the "makepy" 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've posted. (As an aside, obviously I'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's post is relevant to this topic. )<BR><BR>HTH,
<BR><BR>Walter<BR></BODY></HTML>