Cython is a programming language that can write both C and Python, and his goal is to become a superset of the Python language , providing high-level, object-oriented, functional, dynamic programming capabilities for Python. Unlike pure Python, it provides a declaration statement for a variable type. Cython is also a compiler that compiles python and compiles code for Cython languages. Its goal is to have pythoner write C extensions as simple as writing Python .
Cython can:
- Compile your Python code into a C language file, and also roll back from a C language file to a python file
- By adding a type declaration, you can simply convert the readable Python code to an efficient C code
- Raise bugs at the level of the source
- Ability to efficiently interact with large data sets, such as using multidimensional numpy sequences
- Quickly write your app by using the Cython ecosystem
- Simple integration of common C libraries and programs to develop
The Cython compiler is able to compile the vast majority of Python code, and the generated C code, usually at run speed, can get a very noticeable boost. So in the Cython language we allow some of the features in C to exist and translate it into very efficient C code. The existence of a variable type declaration statement has two purposes in Cython: to convert a Python variable that is dynamically transformed into a static but efficient C variable, and also to enable the Python language to use the efficient C-language function library. Cython thus combined the two systems of C with Python, making him a very versatile programming language.
This is the Cython compiler. Pyx---C-- -So/.dll
A simple example of Cython:
First write a file named Helloworld.pyx
Print (' Hello world! ')
And then we'll write a setup.py file for it.
From Distutils.core import setupfrom cython.build import cythonizesetup ( ext_modules = cythonize ("Helloworld.pyx") )
Run command: Python setup.py build_ext--inplace
At this point you will see a helloworld.so or Helloworld.dll file generated under the current folder.
Enter the Python IDE, enter import HelloWorld try and we'll see Hello world! The display.
What's this?-cython language Brief introduction