来自自由进口的圣经
bibles.print(“ Gen”,1,1)
我的目标是输入经文,并将经文保存到文本文件中
您所写的问题并没有多大意义,但是标题确实有意义,所以我将回答它。将bibles.print("Gen", 1, 1)
的输出保存到文件中的方法如下:
from freebible import bibles
def save_to_file(book, chapter, verse, fname=None):
if fname is None:
fname = f'{book}_{chapter}_{verse}.txt'
text = bibles.print(book, chapter, verse)
with open(fname, 'w') as f:
# Change to f.write(str(text[0]) + '\n') if you want the Japanese text
f.write(str(text[-1]) + '\n')
if __name__ == '__main__':
save_to_file("Gen", 1, 1)
脚本会默认将书的文本保存到名为book
_chapter
_verse
.txt的文件中,或者如果您不喜欢,可以指定文件名。该功能将book
,chapter
和verse
作为输入。您可以修改以使脚本将这些作为命令行参数,并将其传递给上面的函数(如果这对您有用)。
示例用法:
(so) Matthews-MacBook-Pro:bible matt$ ls
bible.py
(so) Matthews-MacBook-Pro:bible matt$ python bible.py
[Ge 1:1] 元始に神天地を創造たまへり
[Gen 1:1] In the beginning God created the heavens and the earth.
(so) Matthews-MacBook-Pro:bible matt$ ls
Gen_1_1.txt bible.py
(so) Matthews-MacBook-Pro:bible matt$ cat Gen_1_1.txt
[Gen 1:1] In the beginning God created the heavens and the earth.
HTH。