[英]Run Jupyter Notebook from a Python file
我正在嘗試從 Python 文件在不同的 Jupyter Notebooks 中運行代碼。 有解決辦法嗎?
執行 API 可以滿足您的要求。 從文檔:
import nbformat
from nbconvert.preprocessors import ExecutePreprocessor
# Load your notebook
with open(notebook_filename) as f:
nb = nbformat.read(f, as_version=4)
# Configure
ep = ExecutePreprocessor(timeout=600, kernel_name='python3')
# Execute
ep.preprocess(nb, {'metadata': {'path': 'notebooks/'}})
# Save output notebook
with open('executed_notebook.ipynb', 'w', encoding='utf-8') as f:
nbformat.write(nb, f)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.