Python圣经经文查找

use*_*040 1 python parsing

我对python相当陌生,我正在努力学习。我正在编写一个程序,该程序将导入一个包含国王詹姆斯圣经的文本文件。用户必须输入圣经经文,例如 gen 1:1 或 gen 1:1-10,它会在输入原始数据时显示该节或多节经文,到目前为止我已经将其发送到程序接收文件并拆分的位置数据输入我不确定我可以使用 python 的哪些功能来完成这个

bible = open("kjv.txt" , "r").readlines()
 for line in bible:
  x = line.split("|")
  print "%s, %s, %s" % (x[0], x[1], x[2])
Run Code Online (Sandbox Code Playgroud)

文本文件外观示例

0 | gen 1:1 | In the beginning God created the heaven and the earth. 
1 | gen 1:2 | And the earth was without form, and void; and darkness was upon the face of the deep. And the Spirit of God moved upon the face of the waters. 
2 | gen 1:3 | And God said, Let there be light: and there was light. 
3 | gen 1:4 | And God saw the light, that it was good: and God divided the light from the darkness. 
4 | gen 1:5 | And God called the light Day, and the darkness he called Night. And the evening and the morning were the first day. 
5 | gen 1:6 | And God said, Let there be a firmament in the midst of the waters, and let it divide the waters from the waters. 
6 | gen 1:7 | And God made the firmament, and divided the waters which were under the firmament from the waters which were above the firmament: and it was so. 
7 | gen 1:8 | And God called the firmament Heaven. And the evening and the morning were the second day. 
8 | gen 1:9 | And God said, Let the waters under the heaven be gathered together unto one place, and let the dry land appear: and it was so. 
9 | gen 1:10 | And God called the dry land Earth; and the gathering together of the waters called he Seas: and God saw that it was good. 
Run Code Online (Sandbox Code Playgroud)

teh*_*ckz 6

bibletext = """the bible contents"""

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
Run Code Online (Sandbox Code Playgroud)

这将返回一个bible字典,使用书籍作为键(bible['gen']例如,您可以这样做并获取该书籍的内容)。一本书的内容存储为一个列表列表,如下所示:

[['1:1', 'In the beginning God created the heaven and the earth.', ['1:2', 'And the earth was without form, and void; and darkness was upon the face of the deep. And the Spirit of God moved upon the face of the waters. ']]
Run Code Online (Sandbox Code Playgroud)

在未来,如果你需要更具体的东西,请注明,在你的问题。