Nov-17-2019, 12:56 PM
I'm trying to learn Python 3 using this Book Learn Python 3 The Hard Way by Zed A. Shaw
![[Image: book.png]](https://i.postimg.cc/TPtKpbRX/book.png)
But Exercise 23's code is not working in my PC (Windows 7 64-bit)
Here are my Code and Error
Can anyone explain to me why my code is not working?
![[Image: book.png]](https://i.postimg.cc/TPtKpbRX/book.png)
But Exercise 23's code is not working in my PC (Windows 7 64-bit)
Here are my Code and Error
Can anyone explain to me why my code is not working?
import sys script, input_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('lang.txt', encoding = 'utf-8') main(languages, input_encoding, error)
Error:λ python ex23.py utf-8 strict
Traceback (most recent call last):
File "ex23.py", line 23, in <module>
main(languages, input_encoding, error)
File "ex23.py", line 6, in main
line = language_file.readline()
File "C:\Users\Evil Patrick\AppData\Local\Programs\Python\Python37\lib\codecs.py", line 322, in decode
(result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf-8' codec can't decode bytes in position 11-12: invalid continuation byte
Languages.txt file https://pastebin.com/JmfjW7E9