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?
1 Answer 1
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.
answered Aug 7, 2011 at 1:25
Ignacio Vazquez-Abrams
804k160 gold badges1.4k silver badges1.4k bronze badges
Sign up to request clarification or add additional context in comments.
Comments
lang-py