Facilitates Cython to complete the encryption of Python core source code

Source: Internet
Author: User

The first step is to generate the Pyx file

For example, generate a function

#-*-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

The second step generates 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
)

Step three run Python setup.py build_ext--inplace
Compiling the Xxx.pyd

Step fourth run the compiled file
#!/usr/bin/python
# Coding=utf-8
Import Strategytestcython
Print Strategytestcython.judge ([1326],["True"])

Results
[' Judge ', 1326]

Facilitates Cython to complete the encryption of Python core source code

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.