<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_ligolw(flags, target, attrs=None, ilwdchar_compat=None, **kwargs):
 """Write this `DataQualityFlag` to the given LIGO_LW Document Parameters flags : `DataQualityFlag`, `DataQualityDict` `gwpy.segments` object to write target : `str`, `file`, :class:`~ligo.lw.ligolw.Document` the file or document to write into attrs : `dict`, optional extra attributes to write into segment tables **kwargs keyword arguments to use when writing See also -------- gwpy.io.ligolw.write_ligolw_tables for details of acceptable keyword arguments """

    if isinstance(flags, DataQualityFlag):
        flags = DataQualityDict({flags.name: flags})
    return write_tables(
        target,
        flags.to_ligolw_tables(ilwdchar_compat=ilwdchar_compat,
                               **attrs or dict()),
        **kwargs
    )