简体   繁体   English

如何在 jupyter notebook 中将一个 ipynb 文件中定义的变量访问到另一个文件中?

[英]How to access variables defined in one ipynb file into another in jupyter notebook?

I want to access variables defined in one ipynb file into another in jupyter notebook.我想将一个 ipynb 文件中定义的变量访问到 jupyter notebook 中的另一个文件中。 My code:我的代码:

mymodel.ipynb
import import_ipynb
import utils

N = 12
utils.ipynb
x, sr = librosa.load(path)
S = librosa.stft(x, N)

Error:错误:

NameError: name 'N' is not defined

I have also tried我也试过

from utils import *

you can use %store command more information can be found here and here您可以使用%store命令,可以在此处此处找到更多信息

in source notebook在源笔记本中

data = 'data to read'
%store data

in destination notebook在目标笔记本中

%store -r data
#now u can access data from source notebook

hope this may help希望这可能会有所帮助

it can be done in the following way它可以通过以下方式完成

In source jupyter notebook file, define the variables with value eg: userName = 'PriyabrataSamantaray'在源 jupyter notebook 文件中,使用值定义变量,例如:userName = 'PriyabrataSamantaray'

In the other destination Jupyter notebook, call the file as below %run /Users/priyabrata.samantaray/ConnString --> here the connString is the name of my source jupyter notebook getusername = userName print(getusername)在另一个目标 Jupyter 笔记本中,调用如下文件 %run /Users/priyabrata.samantaray/ConnString --> 这里的 connString 是我的源 jupyter 笔记本的名称 getusername = userName print(getusername)

the output in the destination Jupyter notebook will be PriyabrataSamantaray This code can be used in Databricks jupyter notebook目标 Jupyter notebook 中的输出将是 PriyabrataSamantaray 此代码可用于 Databricks jupyter notebook

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 vscode:如何自动缩进jupyter notebook ipynb文件? - vscode: how to autoindent jupyter notebook ipynb file? 如何从 Jupyter Notebook 上的 other.ipynb 导入变量? - How to import variables from other .ipynb on Jupyter Notebook? 如何从运行 PySpark 内核的 EMR jupyter notebook 中的另一个 ipynb 文件导入? - How to import from another ipynb file in EMR jupyter notebook which runs a PySpark kernel? 如何从 Jupyter 笔记本上的 * .IPYNB 文件执行 * .PY 文件? - How to execute a * .PY file from a * .IPYNB file on the Jupyter notebook? Jupyter Notebook:导入.ipynb文件,并在其他.ipynb文件中访问它的方法,给出错误 - Jupyter Notebook: Import .ipynb file and access it's method in other .ipynb file giving error 如何直接从终端创建和打开 jupyter notebook ipynb 文件 - How to create and open a jupyter notebook ipynb file directly from terminal 如何从.ipynb(Jupyter Notebook)制作可执行的Python文件? - How to make executable Python file from .ipynb (Jupyter Notebook)? Jupyter Notebook 加载 .ipynb 文件时出错 - Jupyter Notebook error loading an .ipynb file 如何从终端运行 an.ipynb Jupyter Notebook? - How to run an .ipynb Jupyter Notebook from terminal? 我应该如何修改 JSON 元数据以便我可以在 jupyter notebook 中打开 ipynb 文件? - How should I modify the JSON metadata so that I can open a ipynb file in a jupyter notebook?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM