[英]Running a Python script in Jupyter Notebook, with arguments passing
[英]import jupyter notebook script into a python script
我有一個簡單的筆記本腳本:“test_a.ipynb”,其中包含一個 test_a() function。
test_a.ipynb 在 python 腳本中調用:“test_b.py”,方法如下:
get_ipython().run_line_magic('run', 'test_a.ipynb')
def test_b():
test_a()
'test_b' 然后由另一個 python 腳本調用,並以下列方式執行:
from test_b import *
test_b()
錯誤信息是:
NameError: name 'test_a' is not defined
但以下腳本運行良好:
get_ipython().run_line_magic('run', 'test_a.ipynb')
def test_b():
test_a()
#
test_b()
任何幫助表示贊賞。
到目前為止,我發現的唯一解決方案是將 test_b.py 轉換為筆記本腳本,然后一切正常。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.