【问题标题】:Jupyter doesn't recognize super(). Is there a fix?Jupyter 无法识别 super()。有解决办法吗?
【发布时间】:2018-09-15 21:06:37
【问题描述】:

当尝试调用超类中的静态方法时,我可以运行如下代码:

super().doSomething()

在标准 Python 3 中,但相同的代码不能在 Jupyter 中运行。错误信息是

super(): no arguments

我试过了

super(SubClass).doSomething()

但是错误信息是

name 'SubClass' is not defined

即使代码在名为 SubClass 的类中运行。

什么是有效的

SuperClass.doSomething()

这很好,但这意味着使SubClass 成为SuperClass 的子类是不相关的。

所有这些都发生在SubClassSuperClass 的静态方法中。

是我遗漏了什么,还是有解决办法?

【问题讨论】:

    标签: python-3.x jupyter-notebook


    【解决方案1】:

    也许您在 Jupyter 中使用错误的内核运行代码?例如:https://github.com/jupyter/jupyter/issues/270

    Jupyter 只是一个外壳,它运行某些版本的 python 来评估您的代码。

    【讨论】:

    • 当我在我的计算机(通过 conda)和 Google 的 colabratory 上安装的 Jupyter 上运行代码时,也会发生同样的事情。据我所知,这是一个 Jupyter 问题。
    猜你喜欢
    • 2021-01-11
    • 1970-01-01
    • 1970-01-01
    • 2021-06-22
    • 2020-05-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-02-10
    相关资源
    最近更新 更多