Файли
openidea/fixtures/python-app/notebooks/summary.ipynb
T
LU XIANGRUIтаwildcatDownstairs 24598e0dae feat(notebook): convert a notebook to a Python script and back (#6491)
Adds Convert to Python File to the Project view context menu of a .ipynb and Convert to Jupyter Notebook to that of a .py file, both also in Find Action for the active editor.

The script uses # %% cell markers; Markdown and raw cells become commented # %% [markdown] / # %% [raw] cells, and IPython-only lines (%magic, !shell) and whole %%cell-magic cells are commented out so the script runs with plain python. The result is written next to the source without overwriting (<name>-1.py, ...) and opened; an open notebook or script is converted as shown, unsaved edits included. Back to a notebook gives nbformat 4.5 with a Python 3 kernelspec, where # %% / #%% lines start cells and a script without markers becomes one code cell. A notebook that is not nbformat 4 reports an error and writes nothing.

Closes #6372

Co-authored-by: wildcatDownstairs <[email protected]>
2026-11-27 20:42:23 +08:00

63 рядки
1.1 KiB
Plaintext

{
"cells": [
{
"cell_type": "markdown",
"id": "intro",
"metadata": {},
"source": [
"# Task summary\n",
"\n",
"Counts the sample tasks by status."
]
},
{
"cell_type": "code",
"id": "setup",
"metadata": {},
"source": [
"%load_ext autoreload\n",
"!python --version"
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"id": "counts",
"metadata": {},
"source": [
"from collections import Counter\n",
"\n",
"tasks = [(\"write docs\", \"done\"), (\"fix bug\", \"open\"), (\"review\", \"open\")]\n",
"counts = Counter(status for _, status in tasks)\n",
"counts"
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"id": "report",
"metadata": {},
"source": [
"for status, n in sorted(counts.items()):\n",
" print(f\"{status}: {n}\")"
],
"execution_count": null,
"outputs": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"name": "python"
}
},
"nbformat": 4,
"nbformat_minor": 5
}