Session Ready
Exercise

Convert notebooks

nbconvert is very flexible and includes exporter classes that can convert notebooks into many formats, including: 'asciidoc', 'custom', 'html', 'latex', 'markdown', 'notebook', 'pdf', 'python', 'rst', 'script', and 'slides'.

We'll write a single function, called nbconv(), that can export to any of these formats.

To do this, we'll use the get_exporter() function from the exporters module of nbconvert.

After instantiating an exporter, we'll use its from_filename() method to obtain the contents of the converted file that will be returned by nbconv().

The from_filename() method also produces a dictionary of metadata that we will not use in this exercise.

Unlike nbuild(), nbconv() will return a string, rather than a NotebookNode object.

Instructions
100 XP
  • Instantiate the exporter specified by the nbconv() exporter argument.
  • Return the contents of the converted file.