def add_extension_if_needed(filepath, ext, check_if_exists=False):
if not filepath.endswith(ext):<EOL><INDENT>filepath += ext<EOL><DEDENT>if check_if_exists:<EOL><INDENT>if not op.exists(filepath):<EOL><INDENT>raise IOError('<STR_LIT>' + filepath)<EOL><DEDENT><DEDENT>return filepath<EOL>
Add the extension ext to fpath if it doesn't have it.

    Parameters
    ----------
    filepath: str
    File name or path

    ext: str
    File extension

    check_if_exists: bool

    Returns
    -------
    File name or path with extension added, if needed.