This code returns 3 random lines from a file. They are returned in a set and I'd like to print them out in a presentable format. How would you do this?
Original file looks like.
- Divided focus leads to divided results.
- Where I point my attention becomes how I spend my life.
- What is natural is not supernatural.
and 602 other lines.
I've tried without success
print(*sample, end="\n ")
print(*sample, sep="\n")
print('\n'.join(sample))
Here is the code.
import random
with open("/Users/will/Dropbox/zettelkasten/Super Slogans 202012281549.md") as file_in:
lines = []
for line in file_in:
lines.append(line.replace(u'\xa0', u' '))
sample = (f' {random.sample(lines, 3)}')
print(sample)
Here is the output I get.
['- Divided focus leads to divided results.\n', '- Where I point my attention becomes how I spend my life.\n', '- What is natural is not supernatural.\n']
Here is the desired output.
- Divided focus leads to divided results.
- Where I point my attention becomes how I spend my life.
- What is natural is not supernatural.
Aucun commentaire:
Enregistrer un commentaire