File tree Expand file tree Collapse file tree 1 file changed +12
-17
lines changed Expand file tree Collapse file tree 1 file changed +12
-17
lines changed Original file line number Diff line number Diff line change @@ -40,6 +40,7 @@ <h3>Output:</h3>
4040 let pyodideReady = false;
4141 let pyodide = null;
4242
43+ // Function to load Pyodide
4344 async function loadPyodideAndPackages() {
4445 pyodide = await loadPyodide();
4546 pyodideReady = true;
@@ -48,23 +49,17 @@ <h3>Output:</h3>
4849
4950 loadPyodideAndPackages();
5051
52+ // Function to redirect stdout to output div
53+ function redirectOutput() {
54+ pyodide.runPython(`
55+ import sys
56+ import io
57+ sys.stdout = io.StringIO() # Redirect stdout to capture print statements
58+ `);
59+ }
60+
61+ // Button click handler to run code
5162 document.getElementById("runBtn").addEventListener("click", async () => {
5263 const output = document.getElementById("output");
53- if ( ! pyodideReady ) {
54- output . textContent = "⏳ Please wait, Pyodide is still loading..." ;
55- return ;
56- }
57-
58- output . textContent = "" ; // clear old output
59- try {
60- const code = cm . getValue ( ) ;
61- let result = await pyodide . runPythonAsync ( code ) ;
62- output . textContent = result !== undefined ? result . toString ( ) : "✅ Code executed." ;
63- } catch ( err ) {
64- output . textContent = `❌ Error:\n${ err } ` ;
65- }
66- } ) ;
67- </ script >
6864
69- </ body >
70- </ html >
65+ if (!pyodideReady
You can’t perform that action at this time.
0 commit comments