发布时间:2019-09-10 08:54:12编辑:auto阅读(1634)
首先,这个东东貌似只有windows上才能实现,所以,需要部署windows下的相关环境
1、需要安装python
2、安装python的win32com的lib,下载地址:
http://sourceforge.net/projects/pywin32/files/
3、安装本地的web容器,我用的apache的tomcat
4、编写例子:
import uuid
import win32com.server.register
class PythonUtilities:
_public_methods_ = ['SplitString']
_reg_progid_ = "Python.Utilities"
#_reg_clsid_ = "{A6688635-62F5-41cb-AF54-CBA84C2F0F86}"
_reg_clsid = "{"+uuid.uuid1()+"}"
def SplitString(self, val):
return "Hello world ", val
if __name__ == '__main__':
print "Registering COM server..."
win32com.server.register.UseCommandLine(PythonUtilities)
5、编写测试的html页面
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<SCRIPT LANGUAGE="JavaScript">
window.onload = function(){
var obj = new ActiveXObject("Python.Utilities");
alert(obj.SplitString("Hello world"));
}
</SCRIPT>
</head>
<body>
</body>
</html>
6、到命令行执行该python 代码
7、再请求该网页
上一篇: Python 播放声音 音频与beep
下一篇: Python之文件内容修改
47850
46410
37292
34741
29322
25979
24924
19959
19550
18037
5800°
6422°
5937°
5966°
7074°
5921°
5952°
6447°
6409°
7788°