首页 > 其他 > 详细

004 编码解码

时间:2021-03-28 22:19:20      阅读:38      评论:0      收藏:0      [点我收藏+]

 

// 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
文言
吴语
??????
中文
*/

  

004 编码解码

原文:https://www.cnblogs.com/huafan/p/14589359.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!