1

I have a text file that is reading in another application's script. This how it looks like in notepad:

Одинцовская РЭС: М.О., Одинцовский район
Климовская РЭС: М.О., г.о. Подольск
Кульшовская РЭС: М.О., г.о. Подольск

This file is needed for two things: 1. Creating a dict of values, separated by ':'. I use this dict in another part of script 2. Allows user to select desirable value

enter image description here

Here is what user see when he launhes script. When a certain value is selected I have to use it in dictionary. But the problem is that selection is in unicode format (because of features of script building in ArcGIS) while the dictionary's keys are str. So I need a value in dictionary which looks like '\xce\xe4\xe8\xed\xf6\xee\xe2\xf1\xea\xe0\xff \xd0\xdd\xd1' to be converted in unicode. But when I make .encode('utf-8') it throws an error

UnicodeDecodeError: 'ascii' codec can't decode byte 0xce in position 0: ordinal not in range(128)

1 Answer 1

2

This should work

>>> c = b'\xce\xe4\xe8\xed\xf6\xee\xe2\xf1\xea\xe0\xff \xd0\xdd\xd1'
>>> c
b'\xce\xe4\xe8\xed\xf6\xee\xe2\xf1\xea\xe0\xff \xd0\xdd\xd1'
>>> c.decode('unicode_escape')
'Îäèíöîâñêàÿ ÐÝÑ'

The b'' prefix denotes sequence of 8-bit bytes.

Take a look at SO read russian characters

Sign up to request clarification or add additional context in comments.

1 Comment

fine, that works! But is there a method for that, i.e. new_word = b(c)?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.