如何将模块导入Databricks笔记本中的另一个模块?
这是我在 Databricks 中的 config.py
DATA_S3_LOCATION='s3://server-data/data1'
DATA_S3_FILE_TYPE='orc'
DATA2_S3_LOCATION='s3://server-data/data2'
DATA2_S3_FILE_TYPE='orc'
我有 init 。 py 也在这个文件夹中
我试图访问另一个文件中的这些变量
import sys
sys.path.insert(1,'/Users/file')
from file import config
我遇到错误,没有名为文件的模块
This is my config.py in Databricks
DATA_S3_LOCATION='s3://server-data/data1'
DATA_S3_FILE_TYPE='orc'
DATA2_S3_LOCATION='s3://server-data/data2'
DATA2_S3_FILE_TYPE='orc'
I have init . py in this folder as well
I am trying to access these variables in another file
import sys
sys.path.insert(1,'/Users/file')
from file import config
I am facing error , no module named file
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这里有几个方面。
%run ./config
包含当前目录中的笔记本 (doc)__init__.py
等正确的目录布局。在这种情况下,您可以使用 Python 导入。您的存储库目录将自动添加到sys.path
中,您无需修改它。PS 我有一个 示例 存储库,其中包含笔记本和笔记本电脑Python 文件方法。
There are several aspects here.
%run ./config
to include notebook from the current directory (doc)__init__.py
, etc. In this case, you can use Python imports. Your repository directory will be automatically added into asys.path
and you don't need to modify it.P.S. I have an example of repository with both notebooks & Python files approaches.