V
V
Vitaly2019-07-20 19:07:55
Python
Vitaly, 2019-07-20 19:07:55

Why doesn't utf-8 encoding work in python?

I wrote the following code (Atom text editor):

import sys
script, encoding, error = sys.argv

def main(language_file, encoding, errors):
    line = language_file.readline()

    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="utf8")

main(languages, encoding, error)

Output via windows powershell:
5d333c491dc00239011173.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
lexa_gorchakov19, 2019-07-20
@vitsen777

https://ru.stackoverflow.com/questions/255207/pyth...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question