Skip to content
Advertisement

How to Reverse Hebrew String in Python?

I am trying to reverse Hebrew string in Python:

JavaScript

but I get:

JavaScript

Care to explain what I’m doing wrong?

EDIT:

I’m also trying to save the string into a file using:

JavaScript

but now I get:

JavaScript

Any ideas how to fix that, too?

Advertisement

Answer

Adding u in front of the hebrew string works for me:

JavaScript

To your second question, you can use:

JavaScript

To write unicode string to file fileName.

Alternatively, without using codecs, you will need to encode reversed string with utf-8 when writing to file:

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement