Home > Software design >  Set a maximum to the instantiation operator of a class - Python
Set a maximum to the instantiation operator of a class - Python

Time:12-30

I want my code to return a error, if the user enters a to high instantiation operator. Like this:

class test:

    def __init__(self, value):
        if value > 300:
            return ERROR
        else:
            self.value = value
        

But i don't just want to print out an error, i want the console to give an error out.

CodePudding user response:

How about:

def __init__(self, value):
    assert value <= 300
    self.value = value
  • Related