I need to convert html entites like '’' into Unicode strings. I've read html.unescape function can do it, so I gave it a try.
print(html.unescape('’'))
This line, if typed in IDLE (Python Shell), works correctly - quotation appears just as it should. But when a create a .py
file with that line of code and try to compile it, the error happens - UnicodeEncodeError: 'charmap' codec can't encode character '\u2019' in position 0: character maps to <undifined>
.
So why it fails in concole and works in IDLE? And what should I do? I need html entities to be converted as part of a parser I'm writing.