How can I indicate a newline in a string in Python, so that I can write multiple lines to a text file?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
It depends on how correct you want to be.
\nwill usually do the job. If you really want to get it right, you look up the newline character in theospackage. (It’s actually calledlinesep.)Note: when writing to files using the Python API, do not use the
os.linesep. Just use\n; Python automatically translates that to the proper newline character for your platform.