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)