Python: Data Transfer Object

html-agility-pack ironpython python

Question

Problem

I need to read and parse many HTML tables from a customer's website; the data in the tables may differ (length of columns).

I thus created a class for each table, however this process quickly became absurd due to the sheer number of tables I needed to analyze with diverse data.

Question

Is there an alternative to establishing a class for each piece of data I want to transmit when implementing DTOs in Python?

Example

Class

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

Create New Instances

items = []
for tds in trs:
    item = HoldItem()

    if (x == PROP_A):
        item.prop_a = tds.InnerText

    ...
    ...
    ...

    items.append(item)

return items

Switch to the SQLServer database

    for item in items:
        command.AddWithValue("@prop_a", item.prop_a)

Facts

  • I'm using Iron Python.
  • I'm putting the details into a table (SQL Server)
  • I'm parsing the html table using HtmlAgilityPack.
  • I'm browsing the website using a web crawler.
1
4
6/6/2012 7:04:46 PM

Accepted Answer

For your needs, The Messenger object looks appropriate. It is designed to be a means of transferring data.

4
2/3/2019 7:50:33 AM

Popular Answer

Python is flexible.

Override __get__ and __set__ and keep "field values" in an internal dictionary for your class (instance).



Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow