code: def read_text_file(filename, encoding="utf-8"):
      
      try:
          with open(filename, 'r', encoding) as f:
              r = f.read()
      except TypeError:
          with open(filename, 'r') as f:
              r = f.read()
      return r
docs: Reads a file under python3 with encoding (default UTF-8).
      Also works under python2, without encoding.
      Uses the EAFP (https://docs.python.org/2/glossary.html#term-eafp)
      principle.