I am creating a Markov text generator that generates haikus. The function to generate the haiku itself will generate 100 haikus using a for loop. They may look something like:
line1 line2 line3 line1 line2 line3 line1 line2 line3
When I try writing these lines to the file, I want to include a space between each haiku, so it looks like:
line1
line2
line3
line1
line2
line3
line1
line2
line3
How would I make this happen while writing to the file?
Also, sometimes it would not preserve the format... sometimes, it's written as line1line2line3
How would I structure my loop?
I've tried:
def writeToFile():
with open("results.txt", "w") as fp:
count = 0
for haiku in haikuList:
for line in haiku:
for item in line:
fp.write(str(item))
count += 1
print "There are", count, "lines in your file."
haikuList looks like:
[[line1,
line2,
line3],
[line1,
line2,
line3],
[line1,
line2,
line3],
[line1,
line2,
line3]]