Python Code Runner with CodeMirror Syntax Highlighting
Online Python Code Editor
🐍 Python 3
⚡ Output
- numpy
- pandas
- scikit-learn
from js import window
from pyodide import create_proxy
import sys
from io import StringIO
def run_code(event=None):
user_code = window.getEditorValue() # Call the JavaScript function to get the code
output_area = document.getElementById('output')
original_stdout = sys.stdout
sys.stdout = StringIO()
try:
exec(user_code)
output = sys.stdout.getvalue()
except Exception as e:
output_area.innerText = 'Error: ' + str(e)
else:
if output:
output_area.innerText = output
else:
output_area.innerText = 'No output'
finally:
sys.stdout = original_stdout
run_button = document.getElementById('runButton')
run_button.addEventListener('click', create_proxy(run_code))
How to use this Online Python Compiler/Interpreter
➜To run Python code online, just type your Python code in the editor box (left) and click on the Run button. Then, check your output in the Output box (right).
➜ This online coding tool supports Python 3.
➜ Supported libraries for this online Python code executor are: numpy, pandas, and scikit-learn
➜ Try out our editor to practice Python online with our collection of free Python exercises.