如何在 Jupyter Notebook 中 运行 子程序?
How to run subroutines in Jupyter Notebook?
虽然我认识到这可能是一个微不足道的问题,但我在研究该主题时一直很难找到答案。
假设我有一个函数 statistics
,它包含各种子例程,我将它们放在 Jupyter Notebook 顶部的一个单元格中。
稍后我将如何在 Jupyter Notebook 中引用其中一些子例程?假设我想使用我在 statistics
函数中为其创建算法的 linearRegression
子例程。
我收到错误,module 'statistics' has no attribute 'lienarRegression'
据我了解,您有一个函数,其中定义了函数并且想在其他地方使用这些 sub-functions?你不能在 Python 中这样做。在主函数外定义 sub-functions,它应该可以正常工作。
所以,从这里开始:
def Foo():
def Bar():
print("Hello world!")
Bar()
对此:
def Bar():
print("Hello world!")
def Foo():
Bar()
虽然我认识到这可能是一个微不足道的问题,但我在研究该主题时一直很难找到答案。
假设我有一个函数 statistics
,它包含各种子例程,我将它们放在 Jupyter Notebook 顶部的一个单元格中。
稍后我将如何在 Jupyter Notebook 中引用其中一些子例程?假设我想使用我在 statistics
函数中为其创建算法的 linearRegression
子例程。
我收到错误,module 'statistics' has no attribute 'lienarRegression'
据我了解,您有一个函数,其中定义了函数并且想在其他地方使用这些 sub-functions?你不能在 Python 中这样做。在主函数外定义 sub-functions,它应该可以正常工作。
所以,从这里开始:
def Foo():
def Bar():
print("Hello world!")
Bar()
对此:
def Bar():
print("Hello world!")
def Foo():
Bar()