아주 간단한 예는 (노트북 셀에 아래의 코드를 붙여 넣습니다) 것 :
%%javascript
// Function that accepts a string of code
var create_and_execute_cell_below = function (code){
var nb = Jupyter.notebook
// create cell below this one
nb.insert_cell_below()
// select cell below (the one we have created)
var cell = nb.select_next().get_selected_cell()
// set text in the cell
cell.set_text(code)
// execute cell
cell.execute()
}
// run the function created above with code 'k = 1'
// and it will create a new cell, filled with 'k = 1'
// and it will execute that cell.
// if you run this cell using [ctrl] + [enter] only one cell
// will be created.
// if you run this cell using [Shift] + [enter] two cells
// will be created, the one of the [Shift] + [enter] command
// and the one of the function created above with the code.
create_and_execute_cell_below('k = 1')
나는 그것이 도움이되기를 바랍니다.
OTOH, the front-end API could be not very stable and there is a lack of documentation 및 일부 내용이 변경 될 수 있으며 위에 게시 된 코드가 필요한 것을 수행하는 최선의 방법이 아닙니다.
지금은 잘 작동합니다. 청초한. 최소한 명시 적으로 kernel.execute를 사용하지 마십시오. cell.execute는이를 암묵적으로 사용할 수 있습니다. 마술은 다음 세포를 만들고 선택합니다. 그렇지 않으면 작동하지만 나타나지 않습니다. 감사. – user2800464