<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_tables(fname, table_names=None, prefix=None, compress=False, local=False):
 """ Writes tables to a pandas.HDFStore file. Parameters fname : str File name for HDFStore. Will be opened in append mode and closed at the end of this function. table_names: list of str, optional, default None List of tables to write. If None, all registered tables will be written. prefix: str If not None, used to prefix the output table names so that multiple iterations can go in the same file. compress: boolean Whether to compress output file using standard HDF5-readable zlib compression, default False. """

    if table_names is None:
        table_names = list_tables()

    tables = (get_table(t) for t in table_names)
    key_template = '{}/{{}}'.format(prefix) if prefix is not None else '{}'

    # set compression options to zlib level-1 if compress arg is True
    complib = compress and 'zlib' or None
    complevel = compress and 1 or 0

    with pd.HDFStore(fname, mode='a', complib=complib, complevel=complevel) as store:
        for t in tables:
            # if local arg is True, store only local columns
            columns = None
            if local is True:
                columns = t.local_columns
            store[key_template.format(t.name)] = t.to_frame(columns=columns)