can also use Cython to achieve mixed
1 Download Cython. installing with Python setup.py install
21 instances
① Creating the HelloWorld folder
Create Helloworld.pyx, such as the following:
cdef extern from"Stdio.h":
extern int printf (const char *format, ...)
def SayHello ():
printf ("hello,world\n")
② compiled, the most convenient is the use of Python distutils,
Under the HelloWorld folder, create the setup.py, such as the following:
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"]),
]),
)
Compile:
Python setup.py Build
Installation:
Python setup.py Install
After installation. will be in Build/lib.??
? Helloworld.pyd copied to lib/site-packages under folder
Note:
Sometimes we just want to test it. Do not want to install. At this time can put build/lib.??? Folder Helloworld.pyd copied to the current folder
or run the script before Importhelloworld: Import sys;sys.path.append (Pathof helloworld.pyd)
③ Test:
>>>import HelloWorld
>>>helloworld. SayHello ()
Hello,world
Python and c| C + + (ii): Using Cython for mixed