zcs99 2016-12-25 08:08 采纳率: 0%
浏览 1350

IPython Notebook: Javascript/Python 双向通信跑不通

按照博客中所说,javascript可以与ipython 实现双向通信,但是其给出的代码运行后,js中定义变量可以实现,但是ipython的kernel 返回无法实现。有同学们在研究这个吗?

http://www.tuicool.com/articles/naqIza

from IPython.display import HTML
from math import pi, sin
#
input_form = """

Code:
Result:
Execute

"""

javascript = """

function handle_output(out_type, out){ console.log(out_type); console.log(out); var res = null; // if output is a print statement if(out_type == "stream"){ res = out.data; } // if output is a python object else if(out_type === "pyout"){ res = out.data["text/plain"]; } // if output is a python error else if(out_type == "pyerr"){ res = out.ename + ": " + out.evalue; } // if output is something we haven't thought of else{ res = "[out type not implemented]"; } document.getElementById("result_output").value = res; } function exec_code(){ var code_input = document.getElementById('code_input').value; var kernel = IPython.notebook.kernel; var callbacks = {'output' : handle_output}; document.getElementById("result_output").value = ""; // clear output box var msg_id = kernel.execute(code_input, callbacks, {silent:false}); console.log("button pressed"); }

"""

HTML(input_form + javascript)

  • 写回答

1条回答 默认 最新

  • zqbnqsdsmd 2016-12-31 02:42
    关注
    评论

报告相同问题?

悬赏问题

  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料