在IPython内核中执行Python代码

时间:2013-11-30 15:13:00

标签: ipython ipython-notebook

我想在Emacs / Pymacs中复制ipython笔记本功能;我需要一个简单代码的方向,1)将python /“magics”代码发送到ipython内核2)接收显示输出,作为字符串。我发现minrk发现this comment,“ipython内核”示例不起作用,它给出了“ImportError:没有名为zmq.blockingkernelmanager的模块”。

我用其他指针运气好了,最后我登陆了ipython-1.1.0 / IPython / kernel / inprocess / tests / test_kernel.py,我删掉了一个小部分,并编写了一个名为pytexipy的Emacs扩展 - 笔记本。它在Github上

goo.gl/kQzJW1

如果有人知道更好的例子,比如连接到现有的(进程外),我想听听这些。

提前致谢,

1 个答案:

答案 0 :(得分:1)

以下是ipython 3.0的示例。

from IPython.testing.globalipapp import get_ipython
from IPython.utils.io import capture_output
ip = get_ipython()

def run_cell(cmd):
    with capture_output() as io:
        res = ip.run_cell(content)
        print 'suc', res.success
        print 'res', res.result
    res_out = io.stdout
    print 'res out', res_out

content = "print (111+222)"
run_cell(content)
content = "alsdkjflajksf"
run_cell(content)

我很快就会更新

https://github.com/burakbayramli/emacs-ipython