Question

Python doesn't save the file with Hebrew characters. How do I fix this? (Python 2.7)

enter image description here

The example image shows a file in the SPE IDE with a first line of

heb = ["ד" ,"ג" ,"ב", "א", ...]
Was it helpful?

Solution

Add this line at the top of your file to specify the encoding:

# -*- coding: utf-8 -*-

PEP 0263 - Defining Python Source Code Encodings

OTHER TIPS

The editor is trying to save in an encoding that doesn't support the characters you use. Specifying the encoding in the file, with

# -*- coding: utf-8 -*-

And tell SPE to save in UT-F8 (in the settings somewhere).

It's not clear whether the problem is with your IDE or Python.

To get Python to behave properly, you need to declare the source file encoding in the source.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top