import gzip


def open_file(path, mode="r", with_gzip=False):
    """
    Opens a file depending on whether it has or not gzip.
    :param path: Path where the file is located.
    :param mode: Mode to open the file.
    :param with_gzip: Open as a gzip file anyway.
    """
    open_func = open
    if path.endswith(".gz") or with_gzip:
        open_func = gzip.open
    return open_func(path, mode)