user3047917
user3047917

Reputation: 63

python 3.5 appending .txt file not formatting correctly when opened in notepad

I am trying to append to a text file and write on a new line each time I append the file for readability in notepad. I believe this should be simple and researched thoroughly but I am still having an issue. Here is the snippet of code that writes to a .txt file:

appending_Text = data2
with open(file_Name, 'a+') as file:
    file.write(appending_Text)
    file.write('\n')

When I run this code and then check the text file, I get my appended data on the same line. When I open the .txt file using notepad, I want it to look like:

data1
data2

When I open the .txt file using notepad in windows, it looks like:

data1data2

What am I missing?

Upvotes: 0

Views: 290

Answers (1)

user3047917
user3047917

Reputation: 63

I figured out the answer and it's not python related but rather a limitation of notepad in windows. Notepad uses a different new line termination than is used in linux systems. Linux uses '\n' and notepad uses '/r/n'

Upvotes: 0

Related Questions