import sys
script, encoding, er = sys.argv
def main(language_file, encoding, err):
line = language_file.readline()
if line:
print_line(line,encoding,err)
return main(language_file,encoding,err)
def print_line(line,encoding,e):
next_lang = line.strip()
raw_bytes = next_lang.encode(encoding,errors=e)
cooked_string = raw_bytes.decode(encoding,errors=e)
print(raw_bytes,"<===>",cooked_string)
languages= open("languages.txt",encoding="utf-8")
main(languages,encoding,er)
#一定在prompt命令行中运行 python ex23.py utf-8 strict
#第2行 将encoding赋值utf-8 er赋值strict
#第23行 运行主程序 读取language 将err变量给了er也就是还是赋值的strict
#第13行 将e变量给了err也就是还是赋值的strict
#第15 16行 encode用法 .enconde(encoding, errors=...) ...默认为strict 也可为ignor等