我已經成功地將一個文本文件拆分成我想要的句子,用逗號分割文本文件。分割一個文本文件,白色空間pronlem
文本文件:
You will find love in the next week, You will die in the next minute, You will get married and have 7 kids, You will end up in prison
代碼:
from random import sample
Future = open('Future.txt', 'r')
for line in Future:
Truth = line.split(",")
field1 = Truth[0]
print (field1)
然而,當我運行程序我得到的文本文件的第一行,如預期,但然後像4條白線。 如何在所需的場景之後阻止白線出現?
我缺少的東西?你的文本文件只是一行? –
嘗試打印「真相」,你會看到它有你的列表中的所有句子。如果你問我,文本文件只包含一個非空行。 –
你能顯示輸出嗎? –