【发布时间】:2020-01-09 06:55:53
【问题描述】:
假设我有一个名为 my_script.py 的 Python 脚本,其中包含一个名为 my_func() 的函数。我将此脚本导入 Jupyter Notebook,以便在单元格中运行 my_func()。
我的问题是,在my_func()的定义中,如何找到调用它的单元号,以便我可以记录单元号?我可以使用任何 API 吗?
类似
# my_script.py
def my_func():
# find which cell this is called from
cell_number_called_from = some_IPython_history_class_api.get_current_cell()
# log the cell number and do the rest of my things
【问题讨论】:
-
不完全一样,但是有一些说明可以找到调用者here的身份。
-
@AMC 感谢您的提示。它正在工作!
标签: python jupyter-notebook ipython