[Tutor] Python / Windows Question

Alan Gauld alan.gauld at blueyonder.co.uk
Sun Jun 13 12:15:58 EDT 2004


> Thanks for all the replies on my COM question.  My
> takeaway is to avoid COM if possible, and in the
> example I gave it's possible.

Yes, but note that this is a problem with COM not with Python.
If oits possible in COM you can do it using Python, the difficulty 
is figuring out exactly what COM objects exist and what they expect
you to do!

> So I have a more general question about Python scripts
> for Windows.  I would like to write Python scripts
> that can manage some point-and-click tasks in Windows.
>  Is it reasonable to expect that anything I can point
> and click can be scripted by a Python script?

Not really, there is usually a better way.  Even COM 
won't let you do that. It is possible to do anything
in Windows from Python using the win32 package and a few 
other bits n pieces but its at a very technical and 
difficult level - you need dozens of lines of code 
just to emulate a simple mouse operation.

> Is there a common framework for this type of scripting
> or  is this unique in every case?  I that COM would be
> the answer, but maybe I'm missing something.

COM is the framework but sadly its different for each 
application. Even the Microsoft applications aren't 
completely consistent (Outlook is totally different 
in structure from the other office apps for example)

If you can find how to do it in COM then Python is as 
good a language to use as any other COM enabled language, 
and better than some.

> Here's another example that maybe someone can walk me
> through or get me started on.  Suppose I want to write
> a Python script to change my display mode.  Is this
> possible?

I'm sure it is although I'm not sure how! It might be 
easiest to do that via the Registry, and the WSH library 
provides COM objects for accessing the registry.

One thing I think you should do is run, don't walk, 
to your nearest bookshop(Amazoin?) and buy Mark 
Hammond's book "Python Programming on Win32". It is 
the best source of info on using Python and Windows.
(Although it could do with a second edition to 
cover XP and some of the recent Python features etc)

Alan G.



More information about the Tutor mailing list