用python编写com server程序
By 追风逐月 • Apr 19th, 2007 • Category: 技术开发 因为同事工作上需要使用到htmltidy(一个开源的用于规正html代码的工具。用来对html代码进行格式化,效果非常好),但平时使用的是delphi,虽然其主页上提供了delphi的封装包,但是可能是版本比较旧的缘故,无法处理繁体中文和日文。
我看了一下,上面有phthon的封装包,于是试了一下,发现能很好的处理多国语言,于是就想起写一个com server让他调用.
用python实现com非常简单,具体实现可以参考《Python Programming on Win32》,这是一本介绍python window编程,非常经典的书籍。
这里我介绍一下实现步骤:
下载并安装Python wrapper for TidyLib,因为该库依赖于ctypes库,所以您可能还需要安装ctypes库
下载并安装pywin32
实现起来很简单,代码如下:PLAIN TEXT
PYTHON:
#–coding:utf8–
# pytidycom.py
#
# A contrived sample Python server that demonstrates
# wrapping, unwrapping, and passing IDispatch objects.
# Import the utilities for wrapping and unwrapping.
from win32com.server.util import wrap, unwrap
import win32com.client
import tidy
# Although we are able to register our Parent object for debugging,
# […]









