[英]How to import variables from other .ipynb on Jupyter Notebook?
I've seen a lot of other questions here about this topic however none have helped.我在这里看到了很多关于这个主题的其他问题,但是没有一个有帮助。 I am coding on Jupyter Notebook using Python 3, to organize my code I am trying to use 2 different modules for my program.我正在使用 Python 3 在 Jupyter Notebook 上进行编码,以组织我的代码,我试图为我的程序使用 2 个不同的模块。 Thus I have 1 module called let's for simplicity call it abc.ipynb and now created a different module called for simplicity edf.ipynb (Both on Jupyter Notebook)因此,我有一个名为让我们为简单起见将其称为abc.ipynb的模块,现在为简单起见创建了一个名为edf.ipynb的不同模块(均在 Jupyter Notebook 上)
At first i wasn't able to import abc to edf but after importing the import_ipynb package and fixing the PYTHONPATH it worked.起初我无法将 abc 导入 edf,但在导入import_ipynb package 并修复 PYTHONPATH 后它起作用了。
However, now I just want to import variables from abc to edf, I am trying:但是,现在我只想将变量从 abc 导入到 edf,我正在尝试:
All give 1 of below errors:都给出以下错误之一:
Any advice?有什么建议吗? I already created an init .py in my folder however I think it is of no use since I am working with.ipynb我已经在我的文件夹中创建了一个init .py 但是我认为它没有用,因为我正在使用 .ipynb
Try changing the name of the file other than "abc".尝试更改“abc”以外的文件名。 Python already has a module called abc
Python 已经有一个名为abc
的模块
I wanted to do the same thing and found a workaround by creating a function in a separate functions.py file that returns the variable I wanted to pass between files我想做同样的事情,并通过在单独的 functions.py 文件中创建 function 找到了一种解决方法,该文件返回我想在文件之间传递的变量
from functions.py import get_variable
desired_variable = get_variable()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.