Examples of the options

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

Option language: -l or --lang

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)


Option height: -h or --height

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)


Option tab: -t or --tab

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)


/home/tornado/miniconda3/envs/testtutormagic/lib/python3.6/subprocess.py:761: ResourceWarning: subprocess 15675 is still running
  ResourceWarning, source=self)

Option secure: -s or --secure

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)


Option link: -k or --link

Just display a link to pythontutor with your defined code.

Example:


In [6]:
%%tutor -k
a = 1
b = 1
print(a + b)




Option run: -r or --run

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...")


This is run in the notebook as well as in PythonTutor:  2
So, you have access to 'a' and 'b' vars...

In [8]:
print("the value of a from the previous cell is: ", a)


the value of a from the previous cell is:  1

Option cumulative: --cumulative

PythonTutor config: Set the cumulative option to True.

Example:


In [5]:
%%tutor --cumulative
def func():
    return 10
a = func()
print(a)


Option heapPrimitives: --heapPrimitives


In [8]:
%%tutor --heapPrimitives
a = 1
b = 1
print(a + b)


Option textReferences: --textReferences


In [13]:
%%tutor --textReferences --heapPrimitives
a = 1
b = 1
print(a + b)


Option curInstr: --curInstr


In [12]:
%%tutor --curInstr 2
a = 1
b = 1
print(a + b)


Option verticalStack: --verticalStack


In [14]:
%%tutor --verticalStack
a = 1
b = 1
print(a + b)