加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Python > 正文

Skulpt在线模拟运行Python工具

发布时间:2020-12-20 10:29:08 所属栏目:Python 来源:网络整理
导读:1. Skulpt是一个完全依靠浏览器端模拟实现Python运行的工具 2. 不需要预处理、插件或服务器端支持,只需编写python并重新载入即可。 3. 由于代码完全是在浏览器中运行的,所以不必担心“服务器崩溃”问题。 github:https://github.com/skulpt/skulpt ? demo:

1. Skulpt是一个完全依靠浏览器端模拟实现Python运行的工具

2. 不需要预处理、插件或服务器端支持,只需编写python并重新载入即可。

3. 由于代码完全是在浏览器中运行的,所以不必担心“服务器崩溃”问题。

github:https://github.com/skulpt/skulpt

?

demo:

<html> 
<head> 

<script src="dist/skulpt.min.js" type="text/javascript"></script> 
<script src="dist/skulpt-stdlib.js" type="text/javascript"></script> 

</head> 

<body> 

<script type="text/javascript"> 

function outf(text) { 
    var mypre = document.getElementById("output"); 
    mypre.innerHTML = mypre.innerHTML + text; 
} 
function builtinRead(x) {
    if (Sk.builtinFiles === undefined || Sk.builtinFiles["files"][x] === undefined)
            throw "File not found: ‘" + x + "‘";
    return Sk.builtinFiles["files"][x];
}
function runit() { 
   var prog = document.getElementById("yourcode").value; 
   var mypre = document.getElementById("output"); 
   mypre.innerHTML = ‘‘; 
   Sk.pre = "output";
    Sk.configure({ output: outf,read: builtinRead,__future__: Sk.python3}); 

   (Sk.TurtleGraphics || (Sk.TurtleGraphics = {})).target = ‘mycanvas‘;
   var myPromise = Sk.misceval.asyncToPromise(function() {
       return Sk.importMainWithBody("<stdin>",false,prog,true);
   });

   myPromise.then(function(mod) {
       console.log(‘success‘);
   },function(err) {
       console.log(err.toString());
   });
} 
</script> 

<h3>Try This</h3> 
<form> 
<textarea id="yourcode" cols="80" rows="10">
import turtle
print(‘hello‘)
t = turtle.Turtle()
t.color(‘red‘)
t.forward(75)
</textarea><br />
<button type="button" onclick="runit()">Run</button> 
</form> 
<pre id="output" ></pre> 
<div id="mycanvas"></div>

</body> 

</html> 

  

?

?

但是,有的问题,不能识别eval函数,不知道为什么?

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读