ungleich-learning-circle/balazs/python-the-hard-way/ex23/convertor.py

26 lines
616 B
Python
Raw Normal View History

2020-05-25 14:59:22 +00:00
import sys
script, input_encoding, error = sys.argv
print (sys.argv)
def main(language_file, encoding, errors):
line = language_file.readline()
print (line)
if line:
print_line(line, encoding, errors)
return main(language_file, encoding, errors)
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)
languages = open("languages.txt", encoding="utf-8")
main(languages, input_encoding, error)