So far I have gotten to ex23 without much trouble. I have read the issues listed surrounding unicode not working, but I think I am missing something else. I cannot even get it to run and pump out question marks or the boxes. I have searched my code backwards from bottom to top looking for typos or syntax errors. I have read numerous pages on how unicode errors and “continuation byte” errors. I sent an email to the contact email when I purchased this product, but I’m really hoping someone is able to help out.
I found this site (https://stackoverflow.com/questions/12468179/unicodedecodeerror-utf8-codec-cant-decode-byte-0x9c) it talked about a number of things I didn’t understand but saw that people were swapping “UTF-8” with “latin-1”. When I do this, the program does run. Is it my incompetence? Is this something with my computer? I am racking my brain trying to understand why I cannot get this to work correctly.
NOT using the latin-1 for utf-8 "fix"
What I type in Powershell:
python ex23.py utf-8 strict
What my ex23.py looks like:
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("languages.txt", encoding="utf-8") main(languages, input_encoding, error)
PS C:\Python\Learn> python test23.py utf-8 strict
Traceback (most recent call last):
File “test23.py”, line 23, in
main(languages, input_encoding, error)
File “test23.py”, line 6, in main
line = language_file.readline()
File “C:\Users\Levi\AppData\Local\Programs\Python\Python36\lib\codecs.py”, line 321, 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