Блокнот Jupyter: как найти номер ячейки, из которой вызывается функция сценария Python?Python

Программы на Python
Anonymous
Блокнот Jupyter: как найти номер ячейки, из которой вызывается функция сценария Python?

Сообщение Anonymous »

Suppose I have a Python script called my_script.py with a one function called my_func() inside. Я импортирую этот скрипт в блокнот Jupyter, чтобы можно было запускать my_func() в ячейках.

Мой вопрос заключается в том, как в определении my_func() определить, из какого номера ячейки он вызывается, чтобы я мог записать номер ячейки? Any API that I could use?

Something like

# 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


Подробнее здесь: https://stackoverflow.com/questions/596 ... t-function

Вернуться в «Python»