How to overload __init__ method based on argument type?
A much neater way to get ‘alternate constructors’ is to use classmethods. For instance: >>> class MyData: … def __init__(self, data): … “Initialize MyData from a sequence” … self.data = data … … @classmethod … def fromfilename(cls, filename): … “Initialize MyData from a file” … data = open(filename).readlines() … return cls(data) … … @classmethod … … Read more