【Python工具】shedskin 把Python翻译成C++
Shed Skin is an experimental Python-to-C++ compiler designed to speed up the execution of computation-intensive Python programs. It converts programs written in a static subset of Python to C++. The C++ code can be compiled to executable code, which can be run either as a standalone program or as an extension module easily imported and used in a regular Python program.其还支持在Python里嵌入C++代码,并一起编译打包。附件为其详细文档。
以下是一个例子,通过Python求最大子数组之和:
#encoding:utf-8
def get_max_sub_array_sum(L):
maxN=L
sN=L
for x in L:
if sN<0:
sN=0
sN+=x
if sN>maxN:
maxN=sN
return maxN
if __name__ == '__main__':
L=
print get_max_sub_array_sum(L)
L=
print get_max_sub_array_sum(L)
L=
print get_max_sub_array_sum(L)
首先安装shedskin, http://code.google.com/p/shedskin/
在所在目录执行:
>shedskin max_sub_array_sum
结果为在当前目录下生成3个文件,cpp, hpp和Makefile,接着
>make
即生成了一个可执行文件,enjoy it!
页:
[1]