What's this?-cython language Brief introduction

Source: Internet
Author: User

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

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.