I can\'t find a definitive answer for this. As far as I know, you can\'t have multiple __init__
functions in a Python class. So how do I solve this problem?
All of these answers are excellent if you want to use optional parameters, but another Pythonic possibility is to use a classmethod to generate a factory-style pseudo-constructor:
def __init__(self, num_holes):
# do stuff with the number
@classmethod
def fromRandom(cls):
return cls( # some-random-number )