code: def beststr(*strings):
      
      for x in strings:
          try:
              x.encode(sys.stdout.encoding)
          except UnicodeEncodeError:
              pass
          else:
              return x
      raise ValueError('No valid strings found')
docs: Test if the output device can handle the desired strings. The options
      should be sorted by preference. Eg. beststr(unicode, ascii).