0

Hi

I'm trying to strings to be saved into a textfile, however, it does not put
each string onto each line. So instead looking like this,

First
Second
Third

It looks like this,

FirstSecondThird

What do I need to do to get it to write to the next line?

2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by pyTony
0

Many ways, one of cleanest is to use '\n'.join:

strings = '''First
Second
Third'''.split()

with open('output.txt', 'w') as output:
    output.write('\n'.join(strings))

# print it out to test
print(open('output.txt').read())
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.