def read_file(filename, print_error=True):
try:<EOL><INDENT>for encoding in ['<STR_LIT:utf-8>', '<STR_LIT>']:<EOL><INDENT>try:<EOL><INDENT>with io.open(filename, encoding=encoding) as fp:<EOL><INDENT>return fp.read()<EOL><DEDENT><DEDENT>except UnicodeDecodeError:<EOL><INDENT>pass<EOL><DEDENT><DEDENT><DEDENT>except IOError as exception:<EOL><INDENT>if print_error:<EOL><INDENT>print(exception, file=sys.stderr)<EOL><DEDENT>return None<EOL><DEDENT>
Returns the contents of a file.