I am trying to cancel the Hebrew string in Python:
line = 'אבגד' reversed = line[::-1] print reversed
but I get:
UnicodeDecodeError: 'ascii' codec can't decode byte 0x93 in position 0: ordinal not in range(128)
Help explain what I'm doing wrong?
EDIT: The answers are wonderful, thanks! I am also trying to save a string in a file using:
w1 = open('~/fileName', 'w') w1.write(reverseLine)
but now i get:
return codecs.charmap_encode(input,errors,encoding_table) UnicodeEncodeError: 'charmap' codec can't encode characters in position 1-3: character maps to <undefined>
Any ideas how to fix this too?
EDIT: Find a solution, see my answer below. In short, I used
codecs.open('~/fileName', 'w', encoding='utf-8')
instead
open('~/fileName', 'w')
source share