官术网_书友最值得收藏!

Chapter 1. Cython Won't Bite

Cython is much more than a programming language. Its origin can be traced to SAGE, the mathematics software package, where it is used to increase the performance of mathematical computations such as those involving matrices. More generally, I tend to consider Cython as an alternative to SWIG to generate really good Python bindings to native code.

Language bindings have been around for years, and SWIG was one of the first and best tools to generate bindings for multitudes of languages. Cython generates bindings for Python code only, and this single purpose approach means it generates the best Python bindings you can get outside of doing it all manually, which should be attempted only if you're a Python core developer.

For me, taking control of legacy software by generating language bindings is a great way to reuse any software package. Consider a legacy application written in C/C++. Adding advanced modern features such as a web server for a dashboard or message bus is not a trivial thing to do. More importantly, Python comes with thousands of packages that have been developed, tested, and used by people for a long time that can do exactly that. Wouldn't it be great to take advantage of all of this code? With Cython, we can do exactly this, and I will demonstrate approaches with plenty of example codes along the way.

This first chapter will be dedicated to the core concepts on using Cython, including compilation, and should provide a solid reference and introduction for all the Cython core concepts.

In this first chapter, we will cover:

  • Installing Cython
  • Getting started - Hello World
  • Using distutils with Cython
  • Calling C functions from Python
  • Type conversion
主站蜘蛛池模板: 湘乡市| 自贡市| 梧州市| 拉萨市| 承德市| 黔西| 遵义县| 建昌县| 青铜峡市| 专栏| 南溪县| 木兰县| 广昌县| 西青区| 顺昌县| 江陵县| 积石山| 土默特左旗| 仪陇县| 永吉县| 凤凰县| 清原| 宁海县| 资阳市| 昌江| 五寨县| 岳阳市| 滨州市| 桂东县| 大英县| 丹凤县| 伊宁县| 冀州市| 澜沧| 吉木萨尔县| 无棣县| 夏津县| 休宁县| 安丘市| 即墨市| 沭阳县|