MCPcopy Create free account
hub / github.com/GAIR-NLP/factool / run_single

Method run_single

factool/math/tool.py:10–25  ·  view source on GitHub ↗
(self, program)

Source from the content-addressed store, hash-verified

8 pass
9
10 def run_single(self, program):
11 buffer = io.StringIO() # Create an in-memory buffer for the output
12 stdout = sys.stdout # Save the original standard output
13 sys.stdout = buffer # Redirect the standard output to the buffer
14 try:
15 exec(program)
16 except Exception as e:
17 # Handle the error here
18 error_message = str(e)
19 sys.stdout = stdout # Restore the original standard output
20 return error_message
21
22 exec(program)
23 sys.stdout = stdout # Restore the original standard output
24 output = buffer.getvalue() # Get the output from the buffer
25 return output
26
27 def run(self, snippet):
28 if snippet == None:

Callers 1

runMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected