def is_encodable(encoding, text): try: text.encode(encoding, 'strict') except UnicodeEncodeError: return False else: return True CODE_PAGES = [('cp%s' % cp) for cp in ( 437, 737, 775, 850, 852, 855, 857, 860, 861, 862, 863, 865, 866, 869, 874, 932, 936, 949, 950, 1250, 1251, 1252, 1253, 1254, 1255, 1256, 1257, 1258, # not supported by Python: # 858, 1200, 1201, 10000, 10007, 10029, 65000, 65001 )] def check(text): match = [encoding for encoding in CODE_PAGES if is_encodable(encoding, text)] if match: print("%r is encodable to %s" % (text, ', '.join(match))) else: print("%r is not encodable to any code page" % (text,)) check(unichr(0x301)) check(unichr(0x363)) check(unichr(0x2661)) check(unichr(0x5171)) check(unichr(0x141)) check(u"\u2661\u5171") check(u"\u0301\u0363\u2661\u5171") check(u"-\u5171\u0141\u2661\u0363\uDC80")