{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# 生成编译注释" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Writing fib_orig.pyx\n" ] } ], "source": [ "%%file fib_orig.pyx\n", "def fib(n):\n", " a,b = 1,1\n", " for i in range(n):\n", " a,b = a+b, a\n", " return a" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "collapsed": true }, "outputs": [], "source": [ "!cython -a fib_orig.pyx" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "在浏览器中打开 `fib_orig.html` 可以查看内容,`windows` 下打开网页使用:" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "collapsed": true }, "outputs": [], "source": [ "!start fib_orig.html" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "`linux` 下使用:\n", "```\n", "open fib_orig.html\n", "```\n", "\n", "其界面可能如图所示:\n", "![界面](fib_orig.png)\n", "\n", "点击某一行可以查看该 `Python` 代码对应的 `C` 代码。" ] } ], "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.10" } }, "nbformat": 4, "nbformat_minor": 0 }