Spaces:
Sleeping
Sleeping
Fixing bug
Browse files
utils.py
CHANGED
|
@@ -21,9 +21,15 @@ def execute_code(code: str, stdin: str = "") -> tuple:
|
|
| 21 |
"""
|
| 22 |
with capture_output() as (stdout, stderr):
|
| 23 |
try:
|
| 24 |
-
#
|
| 25 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
exec(code, {}, local_vars)
|
|
|
|
| 27 |
return stdout.getvalue().strip(), stderr.getvalue().strip(), None
|
| 28 |
except Exception as e:
|
| 29 |
return stdout.getvalue().strip(), stderr.getvalue().strip(), str(e)
|
|
|
|
| 21 |
"""
|
| 22 |
with capture_output() as (stdout, stderr):
|
| 23 |
try:
|
| 24 |
+
# Create a generator for stdin lines
|
| 25 |
+
inputs = iter(stdin.splitlines())
|
| 26 |
+
|
| 27 |
+
# Proper lambda that accepts optional prompt
|
| 28 |
+
input_override = lambda prompt='': next(inputs, '')
|
| 29 |
+
|
| 30 |
+
local_vars = {"input": input_override}
|
| 31 |
exec(code, {}, local_vars)
|
| 32 |
+
|
| 33 |
return stdout.getvalue().strip(), stderr.getvalue().strip(), None
|
| 34 |
except Exception as e:
|
| 35 |
return stdout.getvalue().strip(), stderr.getvalue().strip(), str(e)
|