Converts a .py python source file to a V.4 .ipynb jupyter/ipython notebook.
Based on this and this posts. Question originally asked on stackoverflow.
Run from the examples folder, and don't forget to add the py2ipynb
path to your system path.
Default:
py2ipynb.py example_default.py example_default.ipynb
Pycharm style:
py2ipynb.py example_pycharmlike.py example_from_pycharmlike.ipynb -c pycharm
Spyder style:
py2ipynb.py example_spyderlike.py example_from_spyderlike.ipynb -c spyder
For default
style, see the source code (look at the if/elif line.startswith
statements).
From this, it seems that generally the markers are # <codecell>
, # <markdowncell
, # <rawcell>
, and the deprecated in V.4 # <htmlcell>
and # <headingcell
.
- pycharm style:
##
- spyder style:
#%%
Use one of the code cell markers first, then in a newline follow by #md
(also # md
, #markdown
, # markdown
), and include your markdown code within a block comment below. Everything till the next cell mark (e.g. ##
if using pycharm style cell markers) will go to a markdown cell.
E.g.
##
# md
"""
# Header
* item 1
* item 2
"""
##
print("hello world")
Simply add in a new line after the cell marker #%matplotlib inline
or # %matplotlib inline
, or instead of inline
any other supported backend.
Add after the cell marker in a new line an optional slide metadata marker #slide: <slide_type>
(also # slide: <slide_type>
), where <slide_type>
can be one of the standard slide types -
, slide
, sub-slide
, fragment
, skip
and notes
.
Default when there is no slide tag is slide
.
E.g.
##
```python
##
# md
# slide:skip
"""
# Header
* item 1
* item 2
"""
##
#slide:slide
print("hello world")
On how to convert the notebook to a static format (including slides format) read this doc-page, or specifically for slides generation this guide is helpful.
See also examples: default | pycharm-style | spyder-style