chore: execute js/py code

This commit is contained in:
sigoden
2024-10-26 08:32:36 +08:00
parent e1a26cb4f2
commit 602ca0535e
2 changed files with 6 additions and 6 deletions
+3 -3
View File
@@ -7,10 +7,10 @@ def run(code: str):
code: Python code to execute, such as `print("hello world")`
"""
old_stdout = sys.stdout
new_stdout = io.StringIO()
sys.stdout = new_stdout
output = io.StringIO()
sys.stdout = output
exec(code)
sys.stdout = old_stdout
return new_stdout.getvalue()
return output.getvalue()