0

I use python to convert Russian character to int style. I know the Russian character int value is less than 256. but I get the value above 1000. how to get correct value? My projcet encoding is ISO-8859-5. code:

#!/usr/bin/python
# -*- coding: iso-8859-5 -*-
rus_str = "бвгдеёжзийя"

for i in rus_str:
    print(ord(i))

Result:

1073
1074
1075
1076
1077
1105
1078
1079
1080
1081
1103
snakecharmerb
  • 47,570
  • 11
  • 100
  • 153
  • Python uses Unicode, not ISO-8859-5, https://stackoverflow.com/questions/3547534/what-encoding-do-normal-python-strings-use – Renat Dec 07 '19 at 11:26
  • 1
    Is there a particular reason why you need the ISO-8859-5 value, or will Unicode do? – Llamax Dec 07 '19 at 11:30
  • if I use Unicode there will be an build error. if I use Unicode there will be an build error.D:\Python\Russian2Octal\env\Scripts\python.exe D:/Python/Russian2Octal/env/Russian2Octal.py File "D:/Python/Russian2Octal/env/Russian2Octal.py", line 3 SyntaxError: Non-UTF-8 code starting with '\xd1' in file D:/Python/Russian2Octal/env/Russian2Octal.py on line 3, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details Process finished with exit code 1 – yangkunvanpersie Dec 09 '19 at 01:17

1 Answers1

0

Actually, ord() function return string representation in Unicode, where all Russian characters have number in range from 1040 to 1103. There is also number 1025 for "ё" and "Ё". For your task, you can encode string and then get ASCII code:

rus_str = "бвгдеёжзийя".encode('ISO-8859-5')

for i in rus_str:
    print(i)

Result:

209
210
211
212
213
241
214
215
216
217
239
Fearkin
  • 1
  • 1
  • thank you . get it! ord() function return string representation in Unicode, where all Russian characters have number in range from 1040 to 1103 – yangkunvanpersie Dec 09 '19 at 01:19