{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# 简介" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 使用 Python 和另一种语言混编的好处" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "至少有以下四个原因:\n", "\n", "1. `Best of both worlds` - 结合两种语言的优点:已经优化和测试过的代码库 + Python 的灵活\n", "- `Python as glue` - **Python** 作为连接的桥梁,将很多其他语言的模块结合到一个大型程序中\n", "- `Speed up Python` - 使用一个更快的语言帮助加速 **Python**\n", "- `Division of labor` - 各司其职,让各个语言做各自更擅长的事情,例如 **Fortran** 进行数组计算,**Python** 处理测试,文件读写,文本处理,数据整理,GUI 生成,HTTP 服务等等。" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 语言扩展工具" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### 打包已有的代码和其他语言的库" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "- 使用手写的扩展模块\n", "- `Cython` - **C/C++**\n", "- `SWIG` - **C/C++**\n", "- `f2py` - **Fortran**\n", "- `ctypes` - 其他语言库" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### 加速 Python" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "- 使用手写的扩展模块\n", "- `Cython`\n", "- `Weave`\n", "- `Shedskin` 和其他模块" ] } ], "metadata": { "kernelspec": { "display_name": "Python 2", "language": "python", "name": "python2" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 2 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython2", "version": "2.7.9" } }, "nbformat": 4, "nbformat_minor": 0 }