file:///D:/搜狗高速下载/【教程】【Python】/【教程 】【iPython 】 Learning IPython for Interactive Computing and Data Visualizatio.PDF
Example – executing C++ code in IPython 113页 2015/8/15 14:03:55
it might be a better idea to use Cython or SciPy.weave。The extension defines a new cell magic named cpp. The idea is that one will be able to write C++ code directly in the cell, and it will be automatically compiled and executed. The cell output will contain the standard output of the code. Here is an explanation of how this extension works:该扩展定义了一个名为CPP的新细胞的魔法。我们的想法是,一个将能直接在单元写C ++代码,并且它将自动编译和执行。所述单元输出将包含代码的标准输出。下面是如何扩建工程的解释:
We create a new class derived from IPython.core.magic.Magics我们创建一个从IPython.core.magic.Magics派生新类
In this class, we create a new method with a cell_magic decorator: it will implement the cpp cell magic在这个类中,我们创建了一个新的方法与cell_magic装饰:将实施的CPP细胞魔法
This method accepts the cell's code as input, writes this C++ code in a temporary file, and calls the g++ compiler to create an executable这个方法接受小区的代码作为输入,在临时文件中写入这个C ++代码,并调用g ++编译器创建可执行
Improving this example 115页 2015/8/15 14:36:28
More generally, the same techniques can be used to run non-Python code in IPython. It may even be possible to share variables between Python and the other languages. 更一般地,相同的技术可以被用来在IPython的运行非Python代码。它甚至有可能共享Python和其它语言之间的变量。
The IPython extensions are particularly powerful in the context of the notebook, because they notably allow the implementation of arbitrarily complex behaviors to the cells' code. IPython的扩展是在笔记本中尤其强大,因为他们特别允许任意复杂行为的实施,细胞的代码。
Rich representations in the frontend
one just needs to implement a method called _repr_*_ with * being svg, png, jpeg, html, json, pretty, or latex. For instance, let's define a class, Disc, with a SVG representation method
Embedding IPython 117页
在各种需要暂停的交互场合
The easiest way to integrate IPython in a program is to call IPython.embed() at any point in your Python program (after import IPython). You can also specify custom options, including the input/output templates in the command-line interface, the startup/exit messages, and so on。You can find more information at http://ipython. org/ipython-doc/stable/interactive/reference.html#embedding-ipython.
Final words
The possibility to create custom interactive widgets in the notebook is planned and is likely to be a major feature of the whole project. More information about the upcoming developments can be found at https://github.com/ipython/ipython/wiki/Roadmap:-IPython and http://ipython.org/_static/sloangrant/sloan-grant.html.
• GitHub project page: https://github.com/ipython/ipython
• Wiki: https://github.com/ipython/ipython/wiki
• User mailing list: http://mail.scipy.org/mailman/listinfo/ipython-user
• Chat room: https://www.hipchat.com/ghSp7E1uY