2

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)

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)

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

Desired output:

0.047
3.75
wim
  • 338,267
  • 99
  • 616
  • 750
Luke
  • 744
  • 2
  • 7
  • 23
  • 3
    Because your `Sublime` is probably is pointing to a Python3 version while the terminal and PyCharm are calling Python2. – Abdou Mar 15 '17 at 19:37
  • @Abdou I'm meaning to use Python 3. – Luke Mar 15 '17 at 19:38
  • Seems like Sublime is already pointing to Python3 if the piece of code is running there without any issues. Perhaps PyCharm and your terminal may need the setup here. – Abdou Mar 15 '17 at 19:44
  • @Abdou wim's solution solved my problem. Sublime was actually pointing at Python2 and it was Sublime throwing the error, not PyCharm/Terminal. Thank you either way. :) – Luke Mar 15 '17 at 19:51

1 Answers1

6

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

Tools -> Build System -> New Build System ...

Add this content:

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

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

wim
  • 338,267
  • 99
  • 616
  • 750
  • Works like a charm! Thank you kind sir. Also, to hit you with another question, if the error was thrown due to a different Python version, what's the core difference between super() in Python 2 and Python 3? – Luke Mar 15 '17 at 19:45
  • 1
    Originally you had to specify the types when calling super. In Python 3, they added some [black magic](http://stackoverflow.com/q/36993577/674039) to remove this boilerplate. In the spirit of tough love for Python 2, nobody bothered to backport that syntax sugar, so you still have to use the crappy old version if you're on Python 2. – wim Mar 15 '17 at 20:02