This is a notebook example to show the abilities of tutormagic
. You can install the extension using pip
or conda
.
pip install tutormagic
or
conda install tutormagic
In [2]:
%load_ext tutormagic
Choose the language you want to use for pythontutor.com. Available options are:
python2
python3
java
javascript
typescript
ruby
c
c++
If this option is not used the default value is python3
.
Example:
In [9]:
%%tutor -l python3
a = 1
b = 2
print(a + b)
Change the height of the output area display in pixels.
Example:
In [3]:
%%tutor -l python3 -h 100
a = 1
b = 2
print(a + b)
Open pythontutor in a new tab. height option will be ignored if tab option is used.
Example:
In [4]:
%%tutor -l python3 -t
a = 1
b = 2
print(a + b)
Open pythontutor using https in a new tab. height and tab options will be ignored if secure option is used.
Example:
In [5]:
%%tutor -l python3 -s
a = 1
b = 2
print(a + b)
Just display a link to pythontutor with your defined code.
Example:
In [6]:
%%tutor -k
a = 1
b = 1
print(a + b)
Use this option if you also want to run the code in the cell in the notebook.
Example:
In [7]:
%%tutor -r
a = 1
b = 1
print("This is run in the notebook as well as in PythonTutor: ", a + b)
print("So, you have access to 'a' and 'b' vars...")
In [8]:
print("the value of a from the previous cell is: ", a)
PythonTutor config: Set the cumulative option to True
.
Example:
In [5]:
%%tutor --cumulative
def func():
return 10
a = func()
print(a)
Example:
In [8]:
%%tutor --heapPrimitives
a = 1
b = 1
print(a + b)
Use text labels for references.
Example:
In [13]:
%%tutor --textReferences --heapPrimitives
a = 1
b = 1
print(a + b)
In [12]:
%%tutor --curInstr 2
a = 1
b = 1
print(a + b)
In [14]:
%%tutor --verticalStack
a = 1
b = 1
print(a + b)