def save(self):
        """
        Save this L{KnownHostsFile} to the path it was loaded from.
        """
        p = self._savePath.parent()
        if not p.isdir():
            p.makedirs()

        if self._clobber:
            mode = "wb"
        else:
            mode = "ab"

        with self._savePath.open(mode) as hostsFileObj:
            if self._added:
                hostsFileObj.write(
                    b"\n".join([entry.toString() for entry in self._added]) +
                    b"\n")
                self._added = []
        self._clobber = False

        Save this L{KnownHostsFile} to the path it was loaded from.
        
stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/client/knownhosts.py