def read_utf8(filepath):
 try:
  f = codecs.open(filepath, encoding='utf_8', mode='r')
 except IOError as ioe:
  sys.stderr.write((("[otmod.py] ERROR: Unable to open '" + filepath) + "' for read.\n"))
  raise ioe
 try:
  textstring = f.read()
  norm_text = unicodedata.normalize('NFKD', textstring)
  return norm_text
 except Exception as e:
  sys.stderr.write((('[otmod.py] ERROR: Unable to read ' + filepath) + ' with UTF-8 encoding using the read_utf8() method.\n'))
  raise e
 finally:
  f.close()

def read_utf8 ( filepath ) : try : f = codecs . open ( filepath , encoding = 'utf_8' , mode = 'r' ) except IOError as ioe : sys . stderr . write ( ( ( "[otmod.py] ERROR: Unable to open '" + filepath ) + "' for read.\n" ) ) raise ioe try : textstring = f . read ( ) norm_text = unicodedata . normalize ( 'NFKD' , textstring ) return norm_text except Exception as e : sys . stderr . write ( ( ( '[otmod.py] ERROR: Unable to read ' + filepath ) + ' with UTF-8 encoding using the read_utf8() method.\n' ) ) raise e finally : f . close ( )
read_utf8() is a function that reads text in as utf-8 nfkd normalized text strings from filepath .