0% found this document useful (0 votes)
7 views1 page

Clean Corrupted Widgets from Notebook

The document contains a Python function that cleans corrupted widget metadata from a Jupyter notebook file. It reads a notebook from a specified input path, removes any 'widgets' metadata, and saves the cleaned notebook to a specified output path. The function also provides console feedback about the cleaning process.

Uploaded by

prakashas404
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views1 page

Clean Corrupted Widgets from Notebook

The document contains a Python function that cleans corrupted widget metadata from a Jupyter notebook file. It reads a notebook from a specified input path, removes any 'widgets' metadata, and saves the cleaned notebook to a specified output path. The function also provides console feedback about the cleaning process.

Uploaded by

prakashas404
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

import json

def clean_widgets_from_notebook(input_path, output_path):


with open(input_path, 'r', encoding='utf-8') as f:
notebook = [Link](f)

if 'widgets' in [Link]('metadata', {}):


print(" 🧹 Removing corrupted widget metadata...")
del notebook['metadata']['widgets']

with open(output_path, 'w', encoding='utf-8') as f:


[Link](notebook, f, indent=2)

print(f" ✅ Cleaned notebook saved to: {output_path}")


# Example usage:
clean_widgets_from_notebook("[Link]", "[Link]")

You might also like