在网页上重播,最好的办法是什么? [英] repl in webpage, best way to go about it?

查看:175
本文介绍了在网页上重播,最好的办法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,所以我在浏览器中尝试一个简单的python repl。我想在文本输入中放入一些python代码,然后按发送按钮,然后返回评估它的结果。

OK, so I am experimenting with a simple python repl in a browser. I want to put some python code in a text input, and then hit the 'send' button, then get back the result of evaluating it.

我正在使用烧瓶,有一个路由,它调用stdlib eval 函数,然后将其发回。我还使用 zeroMQ 和简单的服务器/客户端设置。我觉得我错过了一些东西......

I was using flask, with one route, which called the stdlib eval function, and then sends it back. I was also using zeroMQ with a simple server/client setup. I feel like I am missing something though...

这样做的标准方法是怎样的? repl.it skulpt 正在这样做,但他们正在编译为javascript。 Ipython notebook 正在使用zeroMQ,我不知道他们这样做的确切方式,发送一些python使用pub / sub设置的字符串,然后使用 exec 我认为....

How is the standard way to go about doing this kind of thing? Projects like repl.it and skulpt are doing it but they are compiling to javascript. Ipython notebook is using zeroMQ, well I don't know the exact way they are doing it, sending some python string with a pub/sub setup and then using exec I think....

我在想我会喜欢将repl嵌入到支持多种语言的网页中,但我首先要使用python。也许其他人已经这样做了?任何帮助表示赞赏!

I was thinking I would like to embed repl's into webpages that support many languages, but I am starting with python first. Maybe someone else is doing this already? Any help is appreciated!

推荐答案

IPython笔记本webapp与龙卷风网络服务器讨论,该网络服务器充当ZMQ与内核通信的桥梁,内核可能是python,julia,haskell,OCamel,nodejs,ruby,scala ...对于我所知道的那些。只要内核符合消息规范(并且很好关于编写IHaskell的人的消息传递协议的博客文章)它对于前端是透明的只发送字符串/接收结果。

IPython notebook webapp discuss with a tornado webserver that act as a bridge with ZMQ to talk to kernels, kernels might be python, julia, haskell, OCamel, nodejs, ruby, scala ... for thoses that I know of. As long as a kernel comply to the message spec (and nice blog post about messaging protocol from the guy who wrote IHaskell) it is transparent for the frontend that just send strings/ receive results.

如果你想要一个更独立的版本,你可以看看Min的单细胞演示。但基本上你应该能够在一个页面中嵌入IPython的 kernel.js ,并且只需使用 IPython.kernel.execute(代码,回调)

If you want a more stand-alone version you can look at Min's single cell demo. But basically you should be able to embed IPython's kernel.js in a page, and just use IPython.kernel.execute(code, callbacks).

内核中这项工作的确切方式因语言而异。 Python本身可以这样做,因为你可以在特定的命名空间中评估一大堆代码,对于我无法准确告诉你的其他语言。

The exact way of how this work in the kernel differs from language to language. Python can natively do so as you can eval a buch of code in a specific namespace, for other languages I can't tell you exactly.

我认为不是重新发明重新使用IPython的消息规范和可重用组件会使sens [1]。

Instead of reinventing, I think re-using IPython's message spec and reusable component would make sens[1].

此外,我从可靠的消息来源获悉,IPython希望能够使用语言启动笔记本不同的语言,他们也想要比浏览器中的REPL(如QtConsole)更接近[2]。

Also I've heard from reliable source that IPython want the ability to start notebook with languages in different languages, and that they also want some closer than a REPL (like QtConsole) in the browser[2].

[1]我有偏见,我是一个IPython开发。

[1] I'm biased, I'm an IPython dev.

[2]我们经常谈论的东西,但我们有一些Python主义,我们想首先摆脱它。

[2] That something we often talk about, but we have some Python-ism we want to get rid of first.

这篇关于在网页上重播,最好的办法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆