3

my code is so simple. in handling string on python i don't know the unicode thing. sad.

f = open("~161209.txt", "r")
f.read()

I don't know how to fix this error code is below:

UnicodeDecodeError: 'cp949' codec can't decode byte 0xec in position 121: illegal multibyte sequence
3
  • 1
    have you tried: f = open("~161209.txt", "r", encoding="utf-8") ? Commented May 31, 2017 at 13:58
  • it works....it is so easy.....thank you all your help. thank you Commented May 31, 2017 at 14:09
  • I couldn't not find a suitable duplicate for that one, hence my edit to the question to improve the title and my answer. Commented May 31, 2017 at 14:34

1 Answer 1

6

Python 3 provides encoding support directly through open:

f = open("~161209.txt", "r", encoding="utf-8")

For older versions, you have to use the codecs module or io.open function.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.