From da69e7e24a99ee389d272610efd921f8763f1915 Mon Sep 17 00:00:00 2001 From: Hanzhang ma Date: Mon, 6 May 2024 21:23:52 +0200 Subject: [PATCH] convert jupyter notebook to a python file --- convert.py | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 convert.py diff --git a/convert.py b/convert.py new file mode 100644 index 0000000..6f22a73 --- /dev/null +++ b/convert.py @@ -0,0 +1,11 @@ +import nbformat +from nbconvert import PythonExporter + +with open('main.ipynb', "r", encoding="utf-8") as f: + notebook = nbformat.read(f, as_version = 4) + +exporter = PythonExporter() +python_code, _ = exporter.from_notebook_node(notebook) + +with open('main.py', "w", encoding="utf-8") as f: + f.write(python_code) \ No newline at end of file