I am trying to write three separate line in a text document based on input obtained from a dialogue window. I am sure this is a simple fix but I can’t seem to write the three lines as separate lines. Would someone mind telling me what’s wrong with this bit of code?
file = open('file.txt', 'wb')
file.write('input1')
file.write('input2')
file.write('input3')
The inputs should be on different lines but instead they come out as:
input1input2input3
Instead of:
input1
input2
input3
Try this:
You are appending the newline character
'\n'to advance to the next line.If you use the
withconstruct, it will automatically close the file for you:Also, consider using a different variable name in place of
file.