UnicodeEncodeError: 'charmap' codec can't encode character '\ufeff' in position 0: character maps to <undefined>
问题 I'm working on an application which is using utf-8 encoding. For debugging purposes I need to print the text. If I use print() directly with variable containing my unicode string, ex- print(pred_str) . I get this error: UnicodeEncodeError: 'charmap' codec can't encode character '\ufeff' in position 0: character maps to So I tried print(pred_str.encode('utf-8')) and my output looks like this: b'\xef\xbb\xbfpudgala-dharma-nair\xc4\x81tmyayo\xe1\xb8\xa5 apratipanna-vipratipann\xc4\x81n\xc4\x81m'