Test if the output device can handle the desired strings. The options
    should be sorted by preference. Eg. beststr(unicode, ascii).

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