<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def guess_format( filename, ext, formats, io_table ):
 """ Guess the format of filename, candidates are in formats. """

    ok = False
    for format in formats:
        output( 'guessing %s' % format )
        try:
            ok = io_table[format].guess( filename )
        except AttributeError:
            pass
        if ok: break

    else:
        raise NotImplementedError('cannot guess format of a *%s file!' % ext)

    return format