T
T
tutam2018-07-04 15:22:52
Python
tutam, 2018-07-04 15:22:52

How to make python 2 friends with cyrillic?

How to make the second python work with cyrillic? I looked through a bunch of sources, nothing helped. Tried to write

import sys
reload(sys)
sys.setdefaultencoding('UTF8')
I tried other ways, nothing helped. What should I do if, for example, I parsed json and want to get a value from it (the value is a string with Cyrillic characters), like this
s.decode('utf-8')
s = data['weather'][0]['description'].decode('utf-8')

?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
Sergey Gornostaev, 2018-07-04
@tutam

Read " Unicode HOWTO " to the fullest.
Absolutely not to be used sys.setdefaultencoding()! If such an example is given in some source, know that this source is bad and it is better not to refer to it anymore.
What does "nothing worked" mean? Does the computer shut down when you call the decode method?
Obviously, get it if you want.
PS Python 2 was deprecated 10 years ago.

A
Alex F, 2018-07-04
@delvin-fil

#!/usr/bin/env python2.7
# -*- coding: utf-8 -*-
import locale
locale.setlocale(locale.LC_ALL, 'ru_RU.UTF8')

T
Tim, 2018-07-04
@darqsat

I noticed that more often the IDE does not understand the Cyrillic alphabet, and if you run the file in the terminal, then everything works out correctly and the Cyrillic alphabet is visible. Are you in the same situation?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question