elz*_*rdo 5 python-2.7 jupyter-notebook
我想知道如何在 Jupyter 笔记本中显示单元格编号。
动机:
我正在使用nbformatJupyter notebook 显示信息。
要检索文本和图像信息,我目前依赖于以下execution_count值:
def select_cell(notebook, out_value):
"""
returns the information of a cell
"""
# Notebook formatting defintions
if notebook["nbformat"] < 4:
cell_all = list(notebook["worksheets"][0]["cells"])
key_counter = 'prompt_number'
else:
cell_all = list(notebook["cells"])
key_counter = 'execution_count'
# Finding and returning the relevant cell
for icell, cell in enumerate(cell_all):
try: # Not all Cells have the `key_counts`
if cell[key_counter] == out_value:
return cell
except:
None
return None
Run Code Online (Sandbox Code Playgroud)
通过out_value我指的是在方括号中的数值在左边距这里是一个笔记本说:“出[out_value]:”。
并且notebook = nbformat.read(file_notebook, 4)。
我认为最好select_cell根据实际单元格值返回单元格而不是循环它。特别是因为out_value每次执行都会更新,其中单元格值是恒定的。
是的,可以计算单元格数,但如果是长笔记本,很容易迷路。