[Solved] Python3 Converting str with screened byte characters to str [closed]


[EDIT]The question was updated and the below was answered based on the original question.


if you fix your input var1 then you can do something like this:

var1 = '{"text":"tool","pos":"\\xd1\\x81\\xd1\\x83\\xd1\\x89\\xd0\\xb5\\xd1\\x81\\xd1\\x82\\xd0\\xb2\\xd0\\xb8\\xd1\\x82\\xd0\\xb5\\xd0\\xbb\\xd1\\x8c\\xd0\\xbd\\xd0\\xbe\\xd0\\xb5"}'
md = {}
for e in var1[1:-1].split(','):
    md[e.split(':')[0][1:-1]] = e.split(':')[1][1:-1]
md['pos'] = (bytes.fromhex(''.join([h for h in md['pos'].split('\\x')]))).decode('utf-8')
print(md)

output:

{'text': 'tool', 'pos': 'существительное'}

2

solved Python3 Converting str with screened byte characters to str [closed]