Writing variables to new line of txt file in python

后端 未结 3 705
伪装坚强ぢ
伪装坚强ぢ 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条回答
  •  -上瘾入骨i
    2021-01-22 20:49

    file7 = open('test_list7_file.txt','a')

    file7.write(var7 + '\n')

    will work fine, BUT IF YOU APPEND TO EXISTING txt file the MOUSE CURSOR needs to be ONE SPACE AFTER THE LAST ENTRY when you save the file for use in your program.

    ~no space and it joins the last entry,

    ~on the next line already when you create you file to be added to, it adds an empty line first

提交回复
热议问题