0

I am reading a first and last name in Python from a file and am having trouble with encoding. I want to print out the name, but am getting "UnicodeEncodeError: 'charmap' codec can't encode character '\u021b' in position 11: character maps to undefined" with this code:

    first = obj.first_name.encode('utf-8')
    last = obj.last_name.encode('utf-8')
    first = first.decode('utf-8')
    last = last.decode('utf-8')
    print(first)

What is the problem?

0

1 Answer 1

2

The problem is that your output terminal/console doesn't have any way of displaying ț. Try chcp 65001 before running the script if you're using Windows.

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.