Spaces:
Runtime error
Runtime error
| import subprocess | |
| def run_python_code(code: str): | |
| try: | |
| with open("temp.py", "w") as f: | |
| f.write(code) | |
| result = subprocess.check_output(["python3", "temp.py"], stderr=subprocess.STDOUT, timeout=5) | |
| return result.decode() | |
| except Exception as e: | |
| return str(e) | |