How to append new data onto a new line

后端 未结 9 1754
一整个雨季
一整个雨季 2020-12-02 16:41

My code looks like this:

def storescores():

   hs = open(\"hst.txt\",\"a\")
   hs.write(name)
   hs.close() 

so if I run it and enter \"Ry

9条回答
  •  执笔经年
    2020-12-02 17:01

    I had the same issue. And I was able to solve it by using a formatter.

    file_name = "abc.txt"
    new_string = "I am a new string."
    opened_file = open(file_name, 'a')
    opened_file.write("%r\n" %new_string)
    opened_file.close()
    

    I hope this helps.

提交回复
热议问题