import gzip
import io


def smart_open(file, mode='rt', encoding='utf-8'):
  """Convenience function for reading compressed or plain text files.

    :param file: The file to read.
    :param encoding: The file encoding.
    """
  if file.endswith('.gz'):
    return gzip.open(file, mode=mode, encoding=encoding, newline='\n')
  return io.open(file, mode=mode, encoding=encoding, newline='\n')