def write(self): with open(self.filename+".tmp", 'w') as fid: yaml.dump(self.data, fid, Dumper=yaml.RoundTripDumper) move(self.filename+".tmp", self.filename)