I am working on a project that uses ace editor.
I want to take the user's inputted python code and run the code and show the user the output. I know that this can be done for javascript but can it be done for python.
Any help would be apreciated.
To do that you have to get server side script support(PHP,ASP,JSP.. )
I can give you example from PHP, You have to send ace editor input to server and get executed output back to the output window, this question is broad, I gave you server side part !
<?php
$myfile = fopen("main.py", "w") or die("Unable to open file!");
$txt = "#print (\"Hello World!\")";
fwrite($myfile, $txt);
fclose($myfile);
$output = `python main.py`;
echo "<pre>$output</pre>";
?>
Further reading DOC
N.B :pyhton should be installed on your server and you should have permissions
The backtick operator is disabled when safe mode is enabled or shell_exec() is disabled.
hope this will be helpful !
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With