我试过这个:
import random
with open('./quotes.txt') as file:
quote = random.choice(file.read().split("%"))
print(quote)
一个名为quotes.txt
的文本文件包含以下内容:
Random quote
- HeyHoo
%
Foo is a great bar to start you off in the morning
- HeyHoo
%
Try sham-foo today! It'll make turn your hair into a bar of gold!
- ShamFoo™️
而且效果很好.你应该look into the split() function&;阅读文档.