利於Cython完成對Python核心源碼的加密
阿新 • • 發佈:2017-12-01
true tcl core 運行 rate time rand 核心 xxx
第一步 生成pyx文件
例如生成函數
# -*- coding:utf8 -*-
import datetime
import random
import numpy as np
import talib as ta
import math
import csv
def Judge(closeArray,isKFinishArray):
isTrue = ("true" == str(isKFinishArray[0]).lower())
result = ["Nothing",closeArray[0]]
listClose=[0,1,2,3]
if isTrue == True:
np.array(listClose)
close = closeArray[0]
result = ["Judge", close]
return result
第二步 生成setup.py
from distutils.core import setup
from distutils.extension import Extension
from Cython.Distutils import build_ext
ext_modules = [Extension("StrategyTestCython",["StrategyTestCython.pyx"])]
setup(
name = "StrategyTestCython pyx",
cmdclass = {‘build_ext‘: build_ext},
ext_modules = ext_modules
)
第三步 運行 python setup.py build_ext --inplace
編譯出XXX.pyd
第四步 運行編譯文件
#!/usr/bin/python
# coding=utf-8
import StrategyTestCython
print StrategyTestCython.Judge([1326],["True"])
結果
[‘Judge‘, 1326]
利於Cython完成對Python核心源碼的加密