B
B
bushmaks2017-10-30 01:27:49
Python
bushmaks, 2017-10-30 01:27:49

How to force Cyrillic output from raw_input() to console in Python2.7?

I can't figure out how in python2.7 to display Russian letters in a user information request, that is, raw_input(" Here! "). I found this way, but it doesn't work for me:

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

import codecs, sys
outf = codecs.getwriter('cp866')(sys.stdout, errors='replace')
sys.stdout = outf
# Не работает на русском все равно
age = raw_input(u"Сколько тебе лет? ")
height = raw_input(u"Каков твой рост? ")
weight = raw_input(u"Сколько ты весишь? ")

print u"Итак, тебе %r лет, в тебе %r см роста и %r кг веса." % (
age, height, weight)

Here's what I get in the terminal:
19, 180 and 70 - what I entered
59f66b141175a994333400.png
. I also tried to substitute .decode('utf8') and .decode('cp886'), it also didn't help

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
sim3x, 2017-10-30
@bushmaks

outf = codecs.getwriter('utf-8')(sys.stdout, errors='replace')

You have a normal bash in macOS, with normal utf8
And that's why python2 tries to use latin1 for output to the console, I don't know
In any case, it's better to use python3

A
Alex F, 2017-10-30
@delvin-fil

import locale
locale.setlocale(locale.LC_ALL, 'ru_RU.utf8')

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question