I'm trying to parse a file. I have a file name kjv.tsv. Inside this file each line include book name, chapter name, verse number, and verse text.
The output should look like this:
(ge, 0, 0, In the beginning God created the heaven and the earth.)
(ge, 0, 1, And the earth was .... upon the face of the waters.)
(ge, 0, 2, And God said, Let there be light: and there was light.)
This is what I got so far. My function name is line I'm defining parse_line:
def parse_line(line):
'''
Converts a line from kjv.tsv into a list of verse information. I.e.
[book name, chapter number, verse number, verse text]
Return a list of verse information
'''
bibletext = open("kjv.tsv" , "r").readlines()
bible = {}
for line in bibletext.splitlines():
number, bv, contents = line.split(" | ")
book, verse = bv.strip().split(" ")
print (book)
print (bible)
if book in bible:
bible[book].append([verse,contents])
else:
bible[book] = [verse,contents]
print (bible)