Q: Parsing blocks of text within a file into objects I have a text file that looks like this: (blocks are separated by an empty line)
#*Approximate Distance Oracles with Improved Query Time.
#@Christian Wulff-Nilsen
#t2015
#cEncyclopedia of Algorithms
#index555036b37cea80f954149ffc

#*Subset Sum Algorithm for Bin Packing.
#@Julián Mestre
#t2015
#cEncyclopedia of Algorithms
#index555036b37cea80f954149ffd

I want to parse each block and stock the result into an object called Document.
Thanks in advance

A: You can try to use python TTP library to convert it in a list of dictionaries:
from ttp import ttp

data = """
#*Approximate Distance Oracles with Improved Query Time.
#@Christian Wulff-Nilsen
#t2015
#cEncyclopedia of Algorithms
#index555036b37cea80f954149ffc

#*Subset Sum Algorithm for Bin Packing.
#@Julián Mestre
#t2015
#cEncyclopedia of Algorithms
#index555036b37cea80f954149ffd
"""

template = """
#*{{ info | ORPHRASE }}
#@{{ author | ORPHRASE }}
#t{{ year }}
#c{{ title | ORPHRASE }}
#index{{ index }}
"""

parser = ttp(data, template)
parser.parse()
res = parser.result(structure="flat_list")
pprint.pprint(res)

# prints:
# [{'author': 'Christian Wulff-Nilsen',
#   'index': '555036b37cea80f954149ffc',
#   'info': 'Approximate Distance Oracles with Improved Query Time.',
#   'title': 'Encyclopedia of Algorithms',
#   'year': '2015'},
#  {'author': 'Julián Mestre',
#   'index': '555036b37cea80f954149ffd',
#   'info': 'Subset Sum Algorithm for Bin Packing.',
#   'title': 'Encyclopedia of Algorithms',
#   'year': '2015'}]

To create an object one need to use classes and assign dictionary values to class properties. However, if the goal is to process data, list of dictionaries should be good enough.
