从另一个Jupyter Notebook导入功能

从另一个Jupyter Notebook导入功能,第1张

从另一个Jupyter Notebook导入功能

nbimporter模块可以帮助我们:

pip install nbimporter

例如,在此目录结构中有两个笔记本:

/src/configuration_nb.ipynb

analysis.ipynb

/src/configuration_nb.ipynb:

class Configuration_nb():    def __init__(self):        print('hello from configuration notebook')

analysis.ipynb:

import nbimporterfrom src import configuration_nbnew = configuration_nb.Configuration_nb()

输出

importing Jupyter notebook from ......srcconfiguration_nb.ipynbhello from configuration notebook

我们还可以从python文件导入和使用模块。

/src/configuration.py

class Configuration():    def __init__(self):        print('hello from configuration.py')

analysis.ipynb:

import nbimporterfrom src import configurationnew = configuration.Configuration()

输出:

hello from configuration.py


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zaji/5629635.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-12-16
下一篇2022-12-15

发表评论

登录后才能评论

评论列表(0条)

    保存