Writing variables to new line of txt file in python

后端 未结 3 706
伪装坚强ぢ
伪装坚强ぢ 2021-01-22 19:51

From other posts, I\'ve learned that \'\\n\' signifies a new line when adding to a txt file. I\'m trying to do just this, but I can\'t figure out the right syntax when an attrib

3条回答
  •  走了就别回头了
    2021-01-22 20:34

    You just need to specify the newline character as a string:

    Eg:

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

提交回复
热议问题