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?