<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def write(self, records=None, path=None, fields=None, append=False, gzip=None):
 """ Write the table to disk. The basic usage has no arguments and writes the table's data to the attached file. The parameters accommodate a variety of use cases, such as using *fields* to refresh a table to a new schema or *records* and *append* to incrementally build a table. Args: records: an iterable of :class:`Record` objects to write; if `None` the table's existing data is used path: the destination file path; if `None` use the path of the file attached to the table fields (:class:`Relation`):
 table schema to use for writing, otherwise use the current one append: if `True`, append rather than overwrite gzip: compress with gzip if non-empty Examples: """

        if path is None:
            if not self.is_attached():
                raise ItsdbError('no path given for detached table')
            else:
                path = self.path
        path = _normalize_table_path(path)
        dirpath, name = os.path.split(path)
        if fields is None:
            fields = self.fields
        if records is None:
            records = iter(self)
        _write_table(
            dirpath,
            name,
            records,
            fields,
            append=append,
            gzip=gzip,
            encoding=self.encoding)

        if self.is_attached() and path == _normalize_table_path(self.path):
            self.path = _table_filename(path)
            self._sync_with_file()