pytutor

An interface to run Phillip Guo's Python Tutor


Keywords
tracing, education, okpy, tutor, debugger, python
License
MIT
Install
pip install pytutor==1.0.0

Documentation

Pytutor

A library for Phillip Guo's (@pgbovine) Python Tutor.

image

Designed for Python 3 - but should be compatible with Python 2.7 as well.

Installation

pip install pytutor

Usage

Generating Traces

from pytutor import generate_trace

modules = {'helper': 'foo = 1'}
setup_code = "y = 4"
trace = generate_trace.run_logger('x = 1 + y' , setup_code , modules)
trace_dict = json.loads(trace)

# from pytutor import server
# server.run_server(trace)
>>> 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": ""
    }
  ]
}

License

MIT License

Credits:

Phillip Guo - Python Tutor Sumukh Sridhara - @sumukh (Modifications to support multiple python files)