def write_table(table, target, tablename=None, ilwdchar_compat=None,<EOL>**kwargs):
if tablename is None:  <EOL><INDENT>tablename = table.meta.get('<STR_LIT>', None)<EOL><DEDENT>if tablename is None:  <EOL><INDENT>raise ValueError("<STR_LIT>"<EOL>"<STR_LIT>")<EOL><DEDENT>try:<EOL><INDENT>llwtable = table_to_ligolw(<EOL>table,<EOL>tablename,<EOL>ilwdchar_compat=ilwdchar_compat or False,<EOL>)<EOL><DEDENT>except LigolwElementError as exc:<EOL><INDENT>if ilwdchar_compat is not None:<EOL><INDENT>raise<EOL><DEDENT>try:<EOL><INDENT>llwtable = table_to_ligolw(table, tablename, ilwdchar_compat=True)<EOL><DEDENT>except Exception:<EOL><INDENT>raise exc<EOL><DEDENT><DEDENT>return write_ligolw_tables(target, [llwtable], **kwargs)<EOL>
Write a `~astropy.table.Table` to file in LIGO_LW XML format

    This method will attempt to write in the new `ligo.lw` format
    (if ``ilwdchar_compat`` is ``None`` or ``False``),
    but will fall back to the older `glue.ligolw` (in that order) if that
    fails (if ``ilwdchar_compat`` is ``None`` or ``True``).