How to run Python code from ace editor

I am working on a project that uses the ace editor .

I want the user to enter python code and run the code and show the result to the user. I know this can be done for javascript, but it can be done for python.

Any help would be appreciated.

+5
source share
1 answer

For this you need to get server side script support (PHP, ASP, JSP ..)

I can give you an example from PHP, you need to send the ace editor input to the server and get the execution result back to the output window, this question is wide, I gave you a part on the server side!

<?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 of the DOC
NB: pyhton must be installed on your server and you must have permissions

The backtick statement is disabled when safe mode is enabled or the shell () is disabled.

Hope this will be helpful!

+1
source

All Articles