将Python和AutoHotkey结合起来
http://www.autohotkey.com/forum/topic53773.html
Q:I am searching for is a way to execute AHK commands from a Python script. Is this possible?
A:Yes. Here is an example.
tested with python2.6, requires AutoHotkey.dll in the working directory or path...
ahkpython.py:
#Persistent
dllcall(A_ScriptParams, "int", 42, "cdecl int")
return
f1::
inputbox, x, enter a numerical parameter for python callback
result := dllcall(A_ScriptParams, "int", x, "cdecl int")
return
ahkpython.ahk
from ctypes import *
ahk = cdll.AutoHotkey
pyclient = create_string_buffer("ahkpython.ahk") # no unicode in ahk
CMPFUNC = CFUNCTYPE(c_int, c_int)
def py_cmp_func(a):
print "ahk: " , a
return a
cmp_func = CMPFUNC(py_cmp_func)
fx = create_string_buffer(str(cast(cmp_func, c_void_p).value))
script = create_string_buffer("""
fx2(msg){
WinActivate %msg%
msgbox in function fx2 with %msg% from python
return "success"
}
""")
ahk.ahkdll(pyclient, "", fx)
ahk.ahkassign(create_string_buffer("fx"), fx)
ahk.addScript(script)
ahk.ahkFunction(create_string_buffer("fx2"), create_string_buffer("Untitled"))
remarks:
create_string_buffer is required because autohotkey.dll exported functions do not work with unicode.
See HotkeyIt's excellent chm help file for documentation on the functions.
相关文档:
参考链接:http://www.woodpecker.org.cn/diveintopython/functional_programming/dynamic_import.html
一 动态导入模块
Python的import不能接受变量,所以应该用 __import__函数来动态导入。
如下的代码无法正常导入模块
modules = ['OpenSSL', 'Crypto', 'MySQLdb', 'sqlite3', 'zope.interface', 'pyasn1', 'twisted ......
1.Python中时间函数有几种不同的表示方法。一种是基于数字的表示方法,另外一种是用一系列值来表示,第三种是用ASCII码字符串的可读形式来表示的元组。 time()函数返回的是从某一时间点算起的秒数,该数值是一个浮点数。根据操作系统的不同,这个时间点也不同。通过求localtime(0)的值可以找到系统的该时间点。 localtime ......
关键字: python com 报告
http://appofis.javaeye.com/blog/417446
python 操作ms office 生成报告相关总结
I. 项目中需要生成word和excel报告,通常有两种方法:基于字符串拼接以及COM调用。
1) 字符串拼接生成office文档的原理: office文档本身可以体现为xml文件格式,尤其是MS Excel
2003,我们可以自己将一 ......
http://bbs.chinaunix.net/thread-1586782-1-1.html
我刚刚用python写了一段操作excel的脚本,目的是把一个excel文件按照某一列中的字段拆分成多个文件,例如按照城市或者省份等,但是发现处理一个1700行的文件拆分成40多个文件时要运行30分钟左右,性能太慢,请高手帮忙看看怎么才能优化性能,谢谢。
新手写的脚本,请不 ......