It prints out the correct data, then keeps running and raises a KeyError
on later data.
Most likely your file ends with a ------
string, so your split
produces a list with an empty string at the very end, which then produces an empty dict, which naturally doesn't have any keys in it.
Easy fix is to just skip the data
if it's empty, or only whitespace, or if record
is empty. More robust fix is to avoid using []
syntax when you can't be sure what keys each dict actually has; use record.get('Name', None)
instead.