Last active
February 27, 2017 21:01
-
-
Save zedshaw/382c1791080df90ef6379f1409112e9d to your computer and use it in GitHub Desktop.
Potential LPy3THW Exercise 23 to teach Encodings
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
languages = [ | |
"Afrikaans", "አማርኛ", "Аҧсшәа", "العربية", | |
"Aragonés", "Arpetan", "Azərbaycanca", "Bamanankan", | |
"বাংলা", "Bân-lâm-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", "Română", "Romani", | |
"Русский", "Seeltersk", "Shqip", "Simple English", | |
"Slovenčina", "کوردیی ناوەندی", "Српски / srpski", | |
"Suomi", "Svenska", "Tagalog", "தமிழ்", | |
"Taqbaylit", "Татарча/tatarça", "తెలుగు", "Тоҷикӣ", | |
"Türkçe", "Українська", "اردو", "Tiếng Việt", | |
"Võro", "文言", "吴语", "ייִדיש", "中文" | |
] | |
def inspect(language_list, encoding, errors): | |
if language_list: | |
next_lang = language_list.pop() | |
lang_raw_bytes = next_lang.encode(encoding, errors=errors) | |
lang_cooked_string = lang_raw_bytes.decode(encoding, errors=errors) | |
print(lang_raw_bytes, "<===>", lang_cooked_string) | |
return inspect(language_list, encoding, errors) | |
encoding, errors = sys.argv[1:] | |
inspect(languages, encoding, errors) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment