Issue
I have a string that looks like this:
>>> st = 'aaaaa\x12bbbbb'
I can convert it to a raw string via:
>>> escaped_st = st.encode('string-escape')
'aaaaa\\x12bbbbb'
How can I convert the escaped string back to the original string? I was trying to do something like this:
escaped_st.replace('\\\\', '\\')
Solution
Decode the encoded string with the same encoding:
>>> st = 'aaaaa\x12bbbbb'
>>> escaped_st = st.encode('string-escape')
>>> escaped_st
'aaaaa\\x12bbbbb'
>>> escaped_st.decode('string-escape')
'aaaaa\x12bbbbb'
Answered By - falsetru
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.