def uni_print(statement, out_file=None):
 if (out_file is None):
  out_file = sys.stdout
 try:
  out_file.write(statement)
 except UnicodeEncodeError:
  new_encoding = getattr(out_file, 'encoding', 'ascii')
  if (new_encoding is None):
   new_encoding = 'ascii'
  new_statement = statement.encode(new_encoding, 'replace').decode(new_encoding)
  out_file.write(new_statement)
 out_file.flush()

def uni_print ( statement , out_file = None ) : if ( out_file is None ) : out_file = sys . stdout try : out_file . write ( statement ) except UnicodeEncodeError : new_encoding = getattr ( out_file , 'encoding' , 'ascii' ) if ( new_encoding is None ) : new_encoding = 'ascii' new_statement = statement . encode ( new_encoding , 'replace' ) . decode ( new_encoding ) out_file . write ( new_statement ) out_file . flush ( )
this function is used to properly write unicode to a file .