Example #1
0
 def _clear_notebook(self, node):                # pragma: no cover
     if NotebookExporter is not None:
         exporter = NotebookExporter()
         exporter.register_preprocessor(ClearOutputPreprocessor(enabled=True))
         cleared,_ = exporter.from_notebook_node(node)
     else:
         stripped_node = v3_strip_output(node)
         cleared = current.writes(stripped_node, 'ipynb')
     return cleared
Example #2
0
 def _clear_notebook(self, node):                # pragma: no cover
     if NotebookExporter is not None:
         exporter = NotebookExporter()
         exporter.register_preprocessor(ClearOutputPreprocessor(enabled=True))
         cleared,_ = exporter.from_notebook_node(node)
     else:
         stripped_node = v3_strip_output(node)
         cleared = current.writes(stripped_node, 'ipynb')
     return cleared
def filter_notebook(expr,in_file,out_file=None):
    
  c = Config() 
  c.FilterCellsPreprocessor.expression = expr

  exporter = NotebookExporter(preprocessors=[FilterCellsPreprocessor], config=c)
  body,resources = exporter.from_file(in_file)

  if out_file:
    write_nb(body,resources,out_file)
    print 'written to: %s \n\n' %out_file
  else:
    return (body,resources)