title: Python: Data Transfer Object
body: <h2>Problem</h2>
  
  <p>I have various html tables that I need to parse/access from my customers web-page, the data on it might vary across the tables (length of columns).</p>
  
  <p>So, what I've done was to create a class for each table but this task became ridiculous, since there are a lot of tables that I need to parse with data varying.</p>
  
  <h2>Question</h2>
  
  <p>Is there any way to implement DTOs in python other than creating a class for each data that I what to transfer?</p>
  
  <h2>Example</h2>
  
  <h3>Class</h3>
  
  <pre><code>class HoldItem():
  
      @property
      def none1(self):
          return self
  
      @property
      def none2(self):
          return self
  
      @property
      def item(self):
          return self
  
      @property
      def plant(self):
          return self
  
      @property
      def location(self):
          return self
  
      @property
      def material(self):
          return self
  
      @none1.setter
      def none1(self, value):
          self.none1 = value
  </code></pre>
  
  <h3>Populate Instances</h3>
  
  <pre><code>items = []
  for tds in trs:
      item = HoldItem()
  
      if (x == PROP_A):
          item.prop_a = tds.InnerText
  
      ...
      ...
      ...
  
      items.append(item)
  
  return items
  </code></pre>
  
  <h3>Transfer to SQLServer Database</h3>
  
  <pre><code>    for item in items:
          command.AddWithValue("@prop_a", item.prop_a)
  </code></pre>
  
  <h2>Facts</h2>
  
  <ul>
  <li>I'm using Iron Python</li>
  <li>I'm transfering the information into a table (SQL Server)</li>
  <li>I'm using HtmlAgilityPack in order to parse the html table</li>
  <li>I'm web-crawling the page
  </ul>