python 文件写入 w写入 , a 追加写入

class Log():

   def toSet(self,str):
      self.str = str
      with open('./log.txt', 'a') as file_object:
         logstr = self.str+'\n-----\n'
         print(logstr.strip())
         file_object.write(logstr)
         file_object.close()

mylog = Log()
mylog.toSet('帝豪国庆再降价2000')