A library for Phillip Guo's (@pgbovine) Python Tutor.
Designed for Python 3
pip install pytutor
import json
from pytutor import generate_trace, server
modules = {'helper': 'foo = 1'}
setup_code = "y = 4"
trace = generate_trace.run_logger('x = 1 + y' , setup_code , modules)
trace_dict = json.loads(trace)
server.run_server(trace) # Serves HTML
>>> trace_dict
{
"code": {
"main_code": "x = 1 + y",
"custom_modules": {
"pg_setup": "y = 4"
},
"helper": "foo = 1"
},
"trace": [
{
"line": 1,
"event": "step_line",
"func_name": "<module>",
"file_name": "<string>",
"globals": {
"y": 4
},
"ordered_globals": [
"y"
],
"stack_to_render": [],
"heap": {},
"stdout": ""
},
{
"line": 1,
"event": "return",
"func_name": "<module>",
"file_name": "<string>",
"globals": {
"y": 4,
"x": 5
},
"ordered_globals": [
"y",
"x"
],
"stack_to_render": [],
"heap": {},
"stdout": ""
}
]
}
MIT License
Phillip Guo - Python Tutor Sumukh Sridhara - @sumukh (Modifications to support multiple python files)