0

I have an ascii string, e.g.

"\u005c\u005c192.150.4.89\u005ctpa_test_python\u005c5.1\u005c\videoquality\u005crel_5.1.1Mx86\u005cblacklevelsetting\u005c\u5e8f\u5217\u5e8f\u5217.xml"

And I want to convert it into unicode and dump into a file, so that it gets dumped like:

"\\192.150.4.89\tpa\tpa_test_python\5.1\videoquality\logs\blacklevelsetting\序列序列.xml"

Please share your thoughts.

Thanks, Abhishek

1 Answers1

0

Use the unicode_escape codec. Python 3 example:

s=rb'\u005c\u005c192.150.4.89\u005ctpa_test_python\u005c5.1\u005cvideoquality\u005crel_5.1.1Mx86\u005cblacklevelsetting\u005c\u5e8f\u5217\u5e8f\u5217.xml'
s=s.decode('unicode_escape')
with open('out.txt','w',encoding='utf8') as f:
    f.write(s)

Output to file:

\\192.150.4.89\tpa_test_python\5.1\videoquality\rel_5.1.1Mx86\blacklevelsetting\序列序列.xml

Note: There was an extra backslash before videoquality that turned the v to a \v character (vertical form feed) that I removed from your example string.

Mark Tolonen
  • 166,664
  • 26
  • 169
  • 251