在伊普顿运行的类似朱庇特的细胞
ipython-cells的Python项目详细描述
iPython单元格
ipython扩展名,用于在.py文件中执行单元jupyter样式。支持jupyter和spyder单元语法。
将开发期间的线性、选择性执行的优势带到了ipython,而没有jupyter的臃肿。
示例
我们可以像jupyter笔记本一样在.py
文件中执行invidual单元。
example.py
# %% cell1a=10print(a)# %% cell2a+=1print(a)
在ipython中:
# load the extension and a .py file%load_extipython_cells%load_fileexample.py# run some cells%cell_runcell110%cell_runcell211# list available cells for running%list_cells['__first','cell1','cell2']
安装
pip install ipython-cells
或者,在ipython启动时自动加载ipython单元格
~/.ipython/profile_default/ipython_config.py
c.InteractiveShellApp.extensions=['ipython_cells']
执行一系列单元格
%load_fileexample.py# run all cells from beginning of file to cell2 (inclusive)%cell_run^cell21011# run all cells from cell1 (inclusive) to end of file%cell_runcell1$1213
自动恢复
# load example.py with autoreloading%load_fileexample.py--autoreload%cell_runcell110# example.py is modified by an external editor (e.g. `a = 10` -> `a = 20`)# File change is detected and automatically reloaded%cell_runcell120
单元格分隔符语法
单元格由特殊注释分隔。支持jupyter和spyder样式的单元格。
示例
# %% foobar_cell
# In[foobar_cell]
# %% foobar_cell some extra text
# In[foobar_cell] some extra text