// encode -> # decode : bytes - string # encode : string - bytes from sys import argv script, encoding, error = argv def print_line(line, encoding, errors): next_lang = line.strip() raw_bytes = next_lang.encode(encoding, errors = errors) cooked_string = raw_bytes.decode(encoding, errors = errors) print(raw_bytes, "<===>", cooked_string) def main(language_file, encoding, errors): line = language_file.readline() if line: print_line(line, encoding, errors) return main(language_file, encoding, errors) languages = open("languages.txt", encoding = "utf-8") main(languages, encoding, error)
/* // languages.txt Afrikaans ???? А?сш?а ??????? Aragonés Arpetan Az?rbaycanca Bamanankan ????? Ban-lam-gú Беларуская Български Boarisch Bosanski Буряад Català Ч?вашла ?e?tina Cymraeg Dansk Deutsch Eesti Ελληνικ? Espa?ol Esperanto ????? Fran?ais Frysk Gaelg Gàidhlig Galego ??? ??????? ?????? Hrvatski Ido Interlingua Italiano ????? ????? Kapampangan ??????? ?аза?ша Kreyòl ayisyen Latga?u Latina Latvie?u L?tzebuergesch Lietuvi? Magyar Македонски Malti ????? ????????? ???????? Bahasa Melayu Монгол Nederlands ????? ???? 日本語 Norsk bokm?l Nouormand Occitan O?zbekcha/?збекча ?????? ?????? ???? Plattdüütsch Polski Português Roman? Romani Русский Seeltersk Shqip Simple English Sloven?ina ?????? ??????? Српски / srpski Suomi Svenska Tagalog ????? ??????? Taqbaylit Татарча/tatar?a ?????? То?ик? Türk?e Укра?нська ???? Ti?ng Vi?t V?ro 文言 吴语 ?????? 中文 */
原文:https://www.cnblogs.com/huafan/p/14589359.html