title: How is the best approach to validate data in python?
body: <p>I am a newbie in Python, and I´m trying to find the best way to validate data.</p>
  
  <p>I have an object of type "well" that has as attributes other objects. Data can come from a XML file or via code. An example can be seen bellow.</p>
  
  <pre class="lang-py prettyprint-override"><code>
  class Well:
      def __init__ (self, name, group):
          self.__name   = name     # Required
          self.__group  = group    # Required
          self.__operate_list = [] # Optional
          self.__monitor_list = [] # Optional
          self.__geometry = None   # Optional
          self.__perf = None       # Optional
          ...
  
  class Operate:
  
      # *OPERATE (*MAX|*MIN) type value (action)
      # *OPERATE (*PENALTY) type (mode) value (action)
      # *OPERATE (*WCUTBACK) type mode v1 (v2 (v3)) (action)
  
      def __init__ (self, att:str, type_:str, value: [], mode=None, action=None):
          self.__att = att
          self.__type_ = type_
          self.__mode = mode
          self.__value_list = value
          self.__action = action        
  </code></pre>
  
  <p>To validate an "operate" for example, i need to check a lot of restrictions and valid values for each attribute. For instance, I have a list of valid "type_" strings and I should assert that type_ is in this list.</p>
  
  <p>1) The best approach to do this is in the constructor? Should I create a method to do this validation? Or should I create a new class only to validade data?     </p>
  
  <p>2) Where should I create these lists of valid values? In the constructor? As global variables?</p>