Lpthw-ex17-the same codes but"UnicodeDecodeError“


I think I have typed the codes correctly.I don’t know what’s wrong with it.
I’m a Chinese,could anyone explain it clearly.Thank you!

There’s an encoding mismatch. It looks like Python defaults to the GBK encoding which chokes on some characters it doesn’t support.

What happens if you try to enforce UTF-8?

in_file = open(from_file, encoding='utf-8')

Actually I think @florian might be onto the right answer, but try: encoding=‘gbk’ instead of utf-8.

A free service run by Zed A. Shaw for learncodethehardway.org.