title: how to add methods to class attributes in python?
body: <p>I'm creating a custom class to store information about a CFD simulation results.</p>
  
  <p>Right now the way it is set up is that it instantiates an empty class object, then used a method called <code>load_mesh</code> which calls an external function to read all the information about the mesh, and return a dictionary of all the information. The <code>load_mesh</code> method then assigns a bunch of class attributes from the values in the dictionary.</p>
  
  <p>The problem is that I am planning to store alot more information than just the mesh, and I dont want to have like 1000 attributes to my class object. I want to store then in appropriate containers(?) that each have their own methods.</p>
  
  <p>For example, my code looks like this currently (some stuff omitted that's unnecessary):</p>
  
  <pre><code>class CFD():
      def __init__(self, infile=None):
          self.file = infile
  
      def load_mesh(self):
          mesh = load_cfd_mesh(self) #calls outside function to load mesh info, uses self.file, returns dict
          self.proj = mesh['proj']
          self.static_items = mesh['static_items']
          self.nnodes = mesh['nnodes']
          self.node_coords = mesh['node_coords']
          self.node_codes = mesh['node_codes']
          self.nelements = mesh['nelements']
          self.element_types = mesh['element_types_str']
          self.node_connectivity = mesh['node_connectivity']
          self.element_node_ids = mesh['element_node_ids']
          self.element_coords = mesh['element_coords']
          self.element_elevs = mesh['element_elevs']
          self.horizontal_units = mesh['horizontal_units']
          self.vertical_units = mesh['vertical_units']
  
  test = CFD('testfile.txt') #instantiate
  test.load_mesh() #load mesh information to attributes
  </code></pre>
  
  <p>Now, I can access any of the mesh information by doing:</p>
  
  <pre><code>test.proj
  self.nnodes
  self.coords
  </code></pre>
  
  <p>etc...</p>
  
  <p>But want I want to do is store all of this information in <code>test.mesh</code>, where <code>test.mesh</code> has all of these attributes but also has the method <code>test.mesh.load()</code>.</p>
  
  <p>I THINK I can do something like this:</p>
  
  <pre><code>class CFD():
      def __init__(self, infile=None):
          self.file = infile
          self.mesh = None
  
      def load_mesh(self):
          mesh = load_cfd_mesh(self) #calls outside function to load mesh info, uses self.file, returns dict
          setattr(self.mesh, 'proj', mesh['proj'])
          #etc....
  </code></pre>
  
  <p>then I'd be able to do:</p>
  
  <pre><code>test = CFD('testfile.txt') #instantiate
  test.load_mesh() #load mesh information to attributes
  test.mesh.proj
  </code></pre>
  
  <p>But I can't figure out how to add the <code>load_mesh</code> method to <code>self.mesh</code>?</p>
  
  <p>How is it possible to achieve the following way of doing this:</p>
  
  <pre><code>test = CFD('testfile.txt') #instantiate
  test.mesh.load() #load mesh information to attributes
  test.mesh.proj
  </code></pre>
  
  <p>Do I have to define another class within the main class? Like <code>class mesh(self):</code></p>
  
  <p>Also, if my proposed way of adding attributes to self.mesh doesn't make sense..please help!</p>