Member since
01-10-2020
26
Posts
0
Kudos Received
0
Solutions
01-23-2020
07:28 AM
You can find the indices and matches of the header with the finditer of the re package. Then, use that to process the rest: import reimport json
thefile = open("file.txt")line = thefile.readline()iter = re.finditer("\w+\s+", line)columns = [(m.group(0), m.start(0), m.end(0)) for m in iter]records = []
while line: line = thefile.readline() record = {}
for col in columns: record[col[0]] = line[col[1]:col[2]] records.append(record)
print(json.dumps(records))
... View more
01-10-2020
01:16 AM
thanks for this information, it is quite helpful!
... View more