<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def read_file(filename, print_error=True):
 """Returns the contents of a file."""

    try:
        for encoding in ['utf-8', 'latin1']:
            try:
                with io.open(filename, encoding=encoding) as fp:
                    return fp.read()
            except UnicodeDecodeError:
                pass
    except IOError as exception:
        if print_error:
            print(exception, file=sys.stderr)
        return None