Python 开发Activex组件方法

yipeiwu_com6年前Python基础
使用win32com模块开发window ActiveX的示例:(如果你还没有装win32com模块的话,请到http://python.net/crew/skippy/win32/Downloads.html下载)。
复制代码 代码如下:

# SimpleCOMServer.py

class PythonUtilities:
_public_methods_ = ['SplitString']
_reg_progid_ = "Python.Utilities"
_reg_clsid_ = "{A6688635-62F5-41cb-AF54-CBA84C2F0F86}"

def SplitString(self, val):
return "Hello world ", val

if __name__ == '__main__':
print "Registering COM server..."
import win32com.server.register
win32com.server.register.UseCommandLine(PythonUtilities)

在console下运行:python SimpleCOMServer.py

在HTML页面中调用该Activex组件:
复制代码 代码如下:


window.onload = function(){
    var obj = new ActiveXObject("Python.Utilities");

    alert(obj.SplitString("Hel"));
}

相关文章

python tkinter canvas 显示图片的示例

先来看一下该方法的说明 create_image(position, **options) [#] Draws an image on the canvas. position I...

python使用adbapi实现MySQL数据库的异步存储

python使用adbapi实现MySQL数据库的异步存储

之前一直在写有关scrapy爬虫的事情,今天我们看看使用scrapy如何把爬到的数据放在MySQL数据库中保存。 有关python操作MySQL数据库的内容,网上已经有很多内容可以参考了...

python中私有函数调用方法解密

本文实例讲述了python中私有函数调用方法。分享给大家供大家参考,具体如下: 与大多数语言一样,Python 也有私有的概念: ① 私有函数不可以从它们的模块外面被调用 ② 私有类方法...

举例讲解Python面相对象编程中对象的属性与类的方法

python 对象的属性 进入正题,来看一个实例来了解python中类,对象中公有属性,私有属性及局部变量,全局变量的区别. root@10.1.6.200:~# cat objec...

Python中实现对Timestamp和Datetime及UTC时间之间的转换

Python项目中很多时候会需要将时间在Datetime格式和TimeStamp格式之间转化,又或者你需要将UTC时间转化为本地时间,本文总结了这几个时间之间转化的函数,供大家参考。 一...