Skip to content

Instantly share code, notes, and snippets.

@ffreitasalves
Created July 29, 2020 01:10
Show Gist options
  • Save ffreitasalves/a2a3fad1b092432272a9ba921fee9e35 to your computer and use it in GitHub Desktop.
Save ffreitasalves/a2a3fad1b092432272a9ba921fee9e35 to your computer and use it in GitHub Desktop.
Modifying multiple existent Ipython Notebooks using nbformat API
import os
import nbformat
warning_message = '### Developers warning: This notebook was generated using XPTO'
nb_warning_cell = nbformat.v4.new_markdown_cell(warning_message)
for root, dirs, files in os.walk("."):
for file in files:
if file[-6:] == '.ipynb':
nb_path = os.path.join(root, file)
current_nb = nbformat.read(nb_path, as_version=4)
current_nb['cells'].insert(0, nb_warning_cell)
nbformat.write(current_nb, nb_path)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment