代码
"""
import sys
script, encoding, error = sys.argv
"""
from sys import argv
script, encoding, error = argv
def main(language_file, encoding, errors):
line = language_file.readline() # https://www.runoob.com/python/file-readline.html
if line:
print_line(line, encoding, errors)
return main(language_file, encoding, errors)
def print_line(line, encoding, errors):
next_lang = line.strip() # https://www.runoob.com/python/att-string-strip.html
raw_bytes = next_lang.encode(encoding, errors = errors) # https://www.runoob.com/python/att-string-encode.html
cooked_string = raw_bytes.decode(encoding, errors = errors) # https://www.runoob.com/python/att-string-decode.html
print(raw_bytes, "<===>", cooked_string)
print(next_lang)
languages = open("languages.txt", encoding = "utf-8")
main(languages, encoding, error)
遇到问题
1、argv的两种写法,不知道有什么不同;
学到的
1、4个方法:.readline(), .strip(), .encode(), .decode(),使用方式在代码里标注了说明链接
2、创建函数def复习。