title: How to implement multiple constructors in python?
body: <p>In python it's not possible to define the <strong>init</strong> function more than once, which, knowing how the language works, it's rather fair. When an object is created, the <strong>init</strong> is called, so, having two of them would create uncertainty. However in some designs such property is desirable. For example:</p>
  
  <pre><code>class Triangle(object):
    def __init__(self,vertices):
      self.v1 = vertices[0]
      self.v2 = vertices[1]
      self.v3 = vertices[2]
  
   def area(self):
     # calculate the are using vertices
     ...
     return result
  
  class Triangle(object):
    def __init__(self,sides):
      self.v1 = sides[0]
      self.v2 = sides[1]
      self.v3 = sides[2]
  
   def area(self):
     # calculate the are using sides
     ...
     return result
  </code></pre>
  
  <p>in such cases we have the same number of attribute to initialize, and also they are correlated so that from one, you can obtain the other.True, in this specific example one could work with the fact that vertices are tuples whilst sides may be floats (or strings or something else) but of course it's not always the case.</p>
  
  <p>One possible solution would be to delegate the initialization process to other functions like:</p>
  
  <pre><code>class Triangle(object):
    def __init__(self):
      self.v1 = None
      self.v2 = None
      self.v3 = None
  
    def byVertices(self,vertices):
      self.v1 = vertices[0]
      self.v2 = vertices[1]
      self.v3 = vertices[2]
  
   def sidesToVertices(self,sides):
      # converts sides to vertices
      ...
      return vertices
  
   def bySides(self,sides):
      vertices = sidesToVertices(sides)
      self.v1 = vertices[0]
      self.v2 = vertices[1]
      self.v3 = vertices[2]
  
   def area(self):
     # calculate the are using vertices
     ...
     return result
  </code></pre>
  
  <p>but it doesn't look very clean, and all the functionalities like "area" would have to check that the attributes are correctly instanciated (or adopt a try/catch) which is a lot of code, plus it undermines the readability of the project. Overall it looks like a cheap trick for the purpose.</p>
  
  <p>Another option would be to tell the instance, what type of attributes you are going to initialize:</p>
  
  <pre><code>class Triangle(object):
    def __init__(self, data, type = "vertices"):
      if type == "sides":
        data = sideToVertices(self,sides)
      else if type == "vertices":
        pass
      else:
        raise(Exception)
  
     self.v1 = data[0]
     self.v2 = data[1]
     self.v3 = data[3]
  
   def sidesToVertices(self,sides):
      # converts sides to vertices
      ...
      return vertices
  
  
  
   def area(self):
     # calculate the are using vertices
  </code></pre>
  
  <p>This other approach seems preferrable, however i'm not sure how much "pythonic" is to introduce logic in the <strong>init</strong>. What are your tought on the matter ? Is there a better way to orchestrate the situation ? </p>