From 602ca0535e8d79e1e9362f870e3583e5bbedfe5b Mon Sep 17 00:00:00 2001 From: sigoden Date: Sat, 26 Oct 2024 08:32:36 +0800 Subject: chore: execute js/py code --- tools/execute_py_code.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'tools/execute_py_code.py') diff --git a/tools/execute_py_code.py b/tools/execute_py_code.py index ad9310c..a8cfe48 100644 --- a/tools/execute_py_code.py +++ b/tools/execute_py_code.py @@ -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() \ No newline at end of file + return output.getvalue() \ No newline at end of file -- cgit v1.2.3