PythonTutor — Visualizing your code execution

Glaucia Esppenchutz
2 min readNov 14, 2022

For newcomers in the programming world, visualizing how your code or how some types of algorithms work, can be confusing. For example, try for the first time to see in your head how a bubble sort or a heap sort algorithm works and you might get a slight headache.

Also, some people come from other areas and decide to learn how to code without the need to start a college degree in computer science. There are many online courses available out there teaching how to start your first web application, or how to do your first data analysis. Still, when you go deeper in your studies you may need another course to introduce you better to the concepts of how your code really works.

I need to confess, as a neurodivergent person, “imagining” in my head each line being executed or how the items of my array are going to behave in sorting algorithms, is very difficult (to not say impossible).

It was in one of my research for visual better explanations that I found PythonTutor:

This simple website can show you using arrows, lines, and colors where the code executor is and where it will go in the next step. And, of course, you can go back and forth if needed.

PythonTutor homepage

Behind the scenes, PythonTutor uses a very simple Python tool: pdb.

pdb or Python Debugger is a built-in library of Python that does exactly the same thing, it executes the code step by step after a starting point. The big point here is joining the visualization with this built-in library.

PythonTutor also has extensions to debug and learn how works in JavaScript, Java, C++, and C.

Hope this tool helps you such as it helped me :)

--

--

Glaucia Esppenchutz

DataOps engineer at AiFi, writting about software engineering and my Autistic life.