What is the best-practice method for verifying constructor params in Python?
I am new to the language, and am using raise:
class Breakfast(object):
def __init__(self, spam=None, eggs=0):
if not spam:
raise Error("Error: no spam")
Is this stupid, or what?
Thanks!
If you are just trying to make sure that required parameters are passed, just leave off the default value. Python will then automatically throw a TypeError if a parameter is missing.