如何在Jupyter笔记本中运行子例程



虽然我认识到这可能是一个琐碎的问题,但在我的主题研究中找到答案很难。

假设我有一个函数, statistics包含各种子列表,并且我将它们放在jupyter笔记本顶部的单元格中。

稍后如何在jupyter笔记本中引用其中一些子列表?假设我想使用linearRegression sub-Routinat,我为statistics函数创建了算法。

我正在收到错误,module 'statistics' has no attribute 'lienarRegression'

因此,据我了解,您的函数在其内部定义了函数,并且想在其他地方使用这些子功能吗?您不能在Python中这样做。定义主函数之外的子函数,并且应该正常工作。

所以,从此开始:

def Foo():
    def Bar():
        print("Hello world!")
    Bar()

def Bar():
    print("Hello world!")
def Foo():
    Bar()

最新更新