Home > Blockchain >  I tried to make a python interpreter using skulpt, but ran into an unexpected error. I want to use i
I tried to make a python interpreter using skulpt, but ran into an unexpected error. I want to use i

Time:12-07

So I am trying to do a python interpreter on my website using skulpt. But im running to some issues and dont know how to fix them. The error will be probably in the js script which is shown below

Error: Uncaught ReferenceError: Sk is not defined at runit (portfolio:33) at HTMLButtonElement.onclick (portfolio:57)

HTML CODE:

<html> 
<head> 
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js" type="text/javascript"></script> 
<script src="http://www.skulpt.org/js/skulpt.min.js" type="text/javascript"></script> 
<script src="http://www.skulpt.org/js/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}); 
   (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="40" rows="10">import turtle

t = turtle.Turtle()
t.forward(100)

print "Hello World" 
</textarea><br /> 
<button type="button" onclick="runit()">Run</button> 
</form> 
<pre id="output" ></pre> 
<!-- If you want turtle graphics include a canvas -->
<div id="mycanvas"></div> 

</body> 

</html> 

I ran out of ideas how to fix this. Here is the documentation > https://skulpt.org/using.html

CodePudding user response:

Just remove www. from script urls.

You should use http://skulpt.org/js/skulpt.min.js instead of http://www.skulpt.org/js/skulpt.min.js

  • Related