def preferredencoding():
 try:
  pref = locale.getpreferredencoding()
  u'TEST'.encode(pref)
 except:
  pref = u'UTF-8'
 return pref

def preferredencoding ( ) : try : pref = locale . getpreferredencoding ( ) . encode ( pref ) except : pref = u'UTF-8' return pref
get preferred encoding .