在jupyter笔记本的python源代码中调用函数

2024-10-02 16:33:59 发布

您现在位置: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'

我正在使用VisualStudio

问题是什么?我如何解决


Tags: 文件代码pyimportaddreturndefas