python activex_如何在python中使用ActiveX控件
匿名用戶
1級
2016-01-23 回答
[html]?view?plaincopy
<span?style="font-family:?Arial,?Verdana,?sans-serif;?white-space:?normal;?background-color:?rgb(255,?255,?255);?">首先,這個東東貌似只有windows上才能實現(xiàn),所以,需要部署windows下的相關(guān)環(huán)境</span>??
1、需要安裝python
2、安裝python的win32com的lib,下載地址:
http://sourceforge.net/projects/pywin32/files/
3、安裝本地的web容器,我用的apache的tomcat
4、編寫例子:
[html]?view?plaincopy
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)??
將這個文件保存到tomcat的webapps下的一個目錄中
5、編寫測試的html頁面
[html]?view?plaincopy
<!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>???
放到python文件的同一個目錄
6、到命令行執(zhí)行該python?代碼
7、再請求該網(wǎng)頁
總結(jié)
以上是生活随笔為你收集整理的python activex_如何在python中使用ActiveX控件的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 华中计算机基础试题,华中科技大学2009
- 下一篇: Linux Shell脚本语句执行失败,