Leonydis137 commited on
Commit
02c72c4
·
verified ·
1 Parent(s): 86b36e2

Create code_runner.py

Browse files
Files changed (1) hide show
  1. tools/code_runner.py +10 -0
tools/code_runner.py ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ import subprocess
2
+
3
+ def run_python_code(code: str):
4
+ try:
5
+ with open("temp.py", "w") as f:
6
+ f.write(code)
7
+ result = subprocess.check_output(["python3", "temp.py"], stderr=subprocess.STDOUT, timeout=5)
8
+ return result.decode()
9
+ except Exception as e:
10
+ return str(e)