1

How can I print (unicode u2019) in python exactly as ? Note: I know that if I do print(text_bytes) that I get b'’', this is not what i want, just . Using python version 3.5.3 on Windows 10.

Code:

text = '’'
text_bytes = text.encode('utf-8')
text_str = str(text_bytes, 'utf-8')
print(text_str)

Result:

File "C:\Python\Python35\lib\encodings\cp850.py", line 19, in encode
return codecs.charmap_encode(input,self.errors,encoding_map)[0]
UnicodeEncodeError: 'charmap' codec can't encode character '\u2019' in position 0: character maps to <undefined>
  • 1
    This code works for me (Python v3.6.3). – Scott Hunter Aug 22 '18 at 02:08
  • `text = '’'` and `print(text)` works for me, using cpython 3.7.0 on win7. Copy-pasted the output line into http://unicode.scarfboy.com/ to verify that it was indeed u+2019 and not a different identical-looking character. Why do you need to byte-encode it and back? edit: your example code also works properly for me as well – Qwertronix Aug 22 '18 at 02:08
  • Yeah I was surprised it wasn't working. Think it's my libraries then? Using version 3.5.3 on Windows 10. – Farhad Abdolhosseini Aug 22 '18 at 02:17
  • See the [this answer](https://stackoverflow.com/a/32176732/5320906) on the possible dupe question. – snakecharmerb Aug 23 '18 at 04:19

0 Answers0