首页 > 解决方案 > 在 jupyter notebook 的 python 源代码中调用函数

问题描述

我的python文件中有这个(称为myLib.py)

def add(x, y):
    return x + y

在我的 jupeter 笔记本中,我有以下代码:

import myLib as myLib
y=myLib.add(1,2)
print(y)

当我运行 jupyter 单元时,我收到此错误:

AttributeError                            Traceback (most recent call last)
<ipython-input-10-9b942a9ce18f> in <module>
      1 import myLib as myLib
----> 2 y=myLib.add(1,2)
      3 print(y)

AttributeError: module 'myLib' has no attribute 'add'

我正在使用视觉工作室

有什么问题,我该如何解决?

标签: pythonjupyter-notebook

解决方案


推荐阅读