super() 在 Sublime Text 中抛出错误,适用于 PyCharm/Terminal [英] super() throwing an error in Sublime Text, works in PyCharm/Terminal

查看:52
本文介绍了super() 在 Sublime Text 中抛出错误,适用于 PyCharm/Terminal的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经生成了以下代码作为作业的一部分.

I've produced the following code as part of an assignment.

class Question:
    """Base class for all questions"""

    question_count = 0

    def __init__(self, desc):
        self.desc = desc

        Question.question_count += 1


class MarkovMM(Question):
    def __init__(self, desc, arrival, service):
        super().__init__(desc)
        if self.desc == "Question 2":
            self.answer = round(1 - (1 - (arrival / service)) - ((1 - (arrival / service)) * (arrival / service)), 3)
        elif self.desc == "Question 3":
            self.answer = round(1 / ((service / 60) - (arrival / 60)), 4)

qu2 = MarkovMM("Question 2", 5, 23)
print(qu2.answer)
qu3 = MarkovMM("Question 3", 6, 22)
print(qu3.answer)

当我通过 PyCharm 和 Ubuntu 终端运行它时,它工作得很好.但是,在 Sublime Text 中运行它会产生以下错误.

When I run it through PyCharm and Ubuntu terminal, it works just fine. However, running it in Sublime Text it produces the following error.

Traceback (most recent call last):
  File "/home/estilen/Dropbox/College/Year_3/CSA2/Python/hello.py", line 20, in <module>
    qu2 = MarkovMM("Question 2", 5, 23)
  File "/home/estilen/Dropbox/College/Year_3/CSA2/Python/hello.py", line 14, in __init__
    super().__init__(desc)
TypeError: super() takes at least 1 argument (0 given)

为什么在 Sublime 中会出现错误,而在 PyCharm 或 Terminal 中却没有?

Why does the error come up in Sublime, but not in PyCharm or Terminal?

所需的输出:

0.047
3.75

推荐答案

您的 sublimetext 使用默认构建系统,即 Python 2.将其配置为在 Python 3 中运行.

Your sublimetext is using the default build system, which is Python 2. Configure it to run in Python 3.

<代码>工具 ->构建系统 ->新构建系统...

添加此内容:

{
    "cmd": ["python3", "-u", "$file"],
    "file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
    "selector": "source.python"
}

使用合理的文件名保存配置,比如python3.sublime-build,然后在Tools -> 中选择这个新创建的构建;使用 ... 构建.

Save the configuration with a sensible filename, say python3.sublime-build, and select this newly created build in Tools -> Build With ....

这篇关于super() 在 Sublime Text 中抛出错误,适用于 PyCharm/Terminal的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆