string - Writing variables to new line of txt file in python -


from other posts, i've learned '\n' signifies new line when adding txt file. i'm trying this, can't figure out right syntax when attribute right before new line.

my code i'm trying this:

for item in list:     open("file.txt", "w") att_file:         att_file.write(variable\n) 

as can see, i'm trying add variable each item in list new line in txt file. what's correct way this?

you need specify newline character string:

eg:

with open("file.txt", "w") att_file:     item in list:         att_file.write(attribute + "\n") 

Comments

Popular posts from this blog

angular - DownloadURL return null in below code -

meteor - inserting data to database gives error "insert failed: Method '/texts/insert' not found" -