Parsing the hierarchical CSV file in Python

Viewed 44

I have a CSV file with logical hierarchical organization like below. (here I used an indentation to show the hierarchy, the original file doesn't have it)

"HEADER", "headerCol1", "headerCol2", ...
   "SUMMARY", "summaryCol1", "summaryCol2", ...
   "BLOCK_TYPE1_HEADER", "blockType1HeaderCol1", "blockType1HeaderCol2", ...
      "BLOCK_TYPE1_CONTENT", "blockType1ContentCol1", "blockType1ContentCol2", ...
      "BLOCK_TYPE1_CONTENT", "blockType1ContentCol1", "blockType1ContentCol2", ...
      "BLOCK_TYPE1_CONTENT", "blockType1ContentCol1", "blockType1ContentCol2", ...
   "BLOCK_TYPE2_HEADER", "blockType2HeaderCol1", "blockType2HeaderCol2", ...
      "BLOCK_TYPE2_CONTENT", "blockType2ContentCol1", "blockType2ContentCol2", ...
      "BLOCK_TYPE2_CONTENT", "blockType2ContentCol1", "blockType2ContentCol2", ...
"TRAILER", "headerCol1", "headerCol2", ...
"HEADER", ...
   ...
"TRAILER", ...

Is there a way in Python world to declaratively configure the structure of the file records and library to use that configuration to parse the file into the objects?

Please advise me a library or framework that can help!

0 Answers
Related