Cython语法融合C和python
1.pip install Cython
2.helloworld目录下创建helloworld.pyx
内容:
cdef extern from"stdio.h":
extern int printf(const char *format, ...)
def SayHello():
printf("hello,world\n")
3.同目录建Setup.py
内容:
from distutils.core import setup
from distutils.extension import Extension
from Cython.Build import cythonize
setup(
name = 'helloworld',
ext_modules=cythonize([
Extension("helloworld", ["helloworld.pyx"]),
]),
)
4.编译
cmd 输入:
python Setup.py build
5.新建__init()__.py
内容:
from helloworld import *
6.helloworld的前一个目录新建test.py
内容:
import helloworld
helloworld.SayHello()
7.cmd 输入:
python test.py