[Tutor] new to python

Walter Prins wprins at gmail.com
Fri Nov 19 14:52:16 CET 2010

On 19 November 2010 00:20, Joel Schwartz <joel at joelschwartz.com> wrote:

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

Sure, I'll just add to what Alan and Emile's already said.

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.

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

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 http://ur.ly/v1Xy and http://ur.ly/v8Ii)

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

As for resources, there's a seemingly decent presentation on Python and COM
and friends here: http://ur.ly/voQt

Also there's Activestate's documentation that's appropriate:

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:

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:

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


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20101119/9ddfbabb/attachment.html>

More information about the Tutor mailing list