Giter Site home page Giter Site logo

odainanna / tutormagic Goto Github PK

View Code? Open in Web Editor NEW

This project forked from kikocorreoso/tutormagic

0.0 0.0 0.0 598 KB

IPython magics to embed pythontutor.com within an IFrame in the IPython notebook using the code from an IPython code cell.

License: MIT License

Python 100.00%

tutormagic's Introduction

tutormagic extension for the Jupyter notebook


Recommendation

Jupyter notebook magics to embed http://www.pythontutor.com within an IFrame in the Jupyter notebook or to open a new tab in the browser using the code from a notebook code cell (using the IPython kernel).

Install

pip install tutormagic

or with conda

conda install -c kikocorreoso tutormagic

or (for the development version)

pip install git+https://github.com/kikocorreoso/tutormagic.git

Tested on Python 2.7.x, 3.4.x, 3.5.x and 3.6.x and IPython/Jupyter 3.x/4.x/5.x.

Usage

First, load the extension:

%load_ext tutormagic

Once loaded, in a code cell in the notebook type the following:

%%tutor --lang python3
# some python code
# ...

to create an IFrame within the notebook with the http://www.pythontutor.com page with the code included in the Jupyter code cell or:

%%tutor --lang python3 --tab
# some python code
# ...

to open http://www.pythontutor.com page in a new browser tab with the code included in the Jupyter code cell.

Options

--lang or -l: it allows you to choose one of the available languages supported by pythontutor. It this option is set then it will consider the code in the cell as Python3 code.

  • %%tutor --lang python3 or %%tutor -l python3 or %%tutor to show a pythontutor IFrame with python3 code.
  • %%tutor --lang python2 or %%tutor -l python2 to show a pythontutor IFrame with python2 code.
  • %%tutor --lang java or %%tutor -l java to show a pythontutor IFrame with java code.
  • %%tutor --lang javascript or %%tutor -l javascript to show a pythontutor IFrame with javascript code.
  • %%tutor --lang typescript or %%tutor -l typescript to show a pythontutor IFrame with typescript code.
  • %%tutor --lang ruby or %%tutor -l ruby to show a pythontutor IFrame with ruby code.
  • %%tutor --lang c or %%tutor -l c to show a pythontutor IFrame with c code.
  • %%tutor --lang c++ or %%tutor -l c++ to show a pythontutor IFrame with c++ code.
https://raw.githubusercontent.com/kikocorreoso/tutormagic/master/imgs/normal.png

--height or -h: it changes the height of the output area display in pixels. It is used to define the height of the IFrame used to embed http://pythontutor.com within the notebook. If the --tab option is used this option will be ignored.

https://raw.githubusercontent.com/kikocorreoso/tutormagic/master/imgs/height.png

--tab or -t: it will open http://pythontutor.com in a new tab instead of within an IFrame within the notebook.

--secure or -s: it will use HTTPS to open PythonTutor.com. This is useful when being used in a notebook that uses SSL.

--link or -k: it will display a link to PythonTutor, not via an iFrame.

https://raw.githubusercontent.com/kikocorreoso/tutormagic/master/imgs/link1.png

--run or -r: Use this option if you also want to run the code in the cell in the notebook.

https://raw.githubusercontent.com/kikocorreoso/tutormagic/master/imgs/run1.png

You can customize how PythonTutor is rendered via the options available below in the URL params. The following options are available:

  • Use the --cumulative option to tell PythonTutor to the cumulative to True
https://raw.githubusercontent.com/kikocorreoso/tutormagic/master/imgs/cumulative1.png
  • Use the --heapPrimitives option to tell PythonTutor to render objects on the heap
https://raw.githubusercontent.com/kikocorreoso/tutormagic/master/imgs/test_heap1.png
  • Use the --textReferences option to tell PythonTutor to use text labels for references
  • Use the --curInstr followed by a number to start the visualisation at the defined step
https://raw.githubusercontent.com/kikocorreoso/tutormagic/master/imgs/current1.png
  • Use the --verticalStack to set visualization to stack atop one another.
https://raw.githubusercontent.com/kikocorreoso/tutormagic/master/imgs/vertical1.png

Examples

Example notebook included in the repository.

Example (in spanish) notebook.

Name of the extension

The name of the extension was suggested by Doug S. Blank (@dsblank).

Changelog

Version 0.3.0

  • Added options --secure, --link, --cumulative, --heapPrimitives and --textReferences (thanks to James Quacinella (@jquacinella)).
  • Added options --run, --curInstr and --verticalStack.

Version 0.2.0

  • Added new --tab option (thanks to Holger Karl (@hkarl)).
  • Added new --height option (thanks to Tom Simonart(@tomsimonart)).
  • Added new languages available on http://pythontutor.com (Typescript, Ruby, C and C++).

Version 0.1.0

  • Initial version

tutormagic's People

Contributors

hkarl avatar jquacinella avatar kikocorreoso avatar odainanna avatar tomsimonart avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.