PythonWindowsTutorial 下载本文

Using Python To Harness Windows

4.9 Debugging

Currently stepping through, at ?print z? line in right pane. ? ? ? ? ?

Conditional breakpoints breakpoints watch list Stack

Code Browser if you wish!

Page 13 of 71

6795.doc

Using Python To Harness Windows

4.10 Grep

…leads to…

Click any line to go to source file.

4.11 Conclusion

? ? ?

evolving fast, extensible

not too shabby for a free editor!

Page 14 of 71

6795.doc

Using Python To Harness Windows

Part 2: - COM

Page 15 of 71

6795.doc

Using Python To Harness Windows

5 Introduction to Python and COM

5.1 What’s COM about anyway?

COM ? ? ? ? ?

Most big apps expose their functionality through COM servers. You can borrow their functionality for your own programs.

Programming for Windows is like being in a sea of objects all waiting to help you.

Discuss: Windows – the most open Operating System?

The Registry: where COM objects find out about each other. (Not just a big INI file!)

Lets objects in different languages talk to each other Lets objects in different processes talk to each other Lets objects on different machines talk to each other Hides the details from the programmer No performance penalties compared to DLLs

5.2 A Minimal COM Client

Connect to Excel and insert some data >>> from win32com.client import Dispatch >>> xlApp = Dispatch(\>>> xlApp.Visible = 1 >>> xlApp.Workbooks.Add() >>> xlSheet.Cells(1,1).Value = 'What shall be the number of thy counting?' >>> xlSheet.Cells(2,1).Value = 3 Remember to install your Office Object Model Documentation!

Page 16 of 71

6795.doc