0

There are million questions and answers related to that but nothing worked with me.

I have a byte string that has escape characters, I want to decode it and convert it to string but without the escape characters and when printed it would be something like the following

>>> normal_string = "Hello\r\nWorld"
>>> print(normal_string)
Hello
World

Here is a part of my byte string

>>> bytes_string = b'Normal sentence\r\n\tIndented sentence\r\nanother one'
>>> converted_string = str(bytes_string, 'utf-8')
>>> print(converted_string)
Normal sentence\r\n\tIndented sentence\r\nanother one

and I want this

>>> print(string_that_I_want)
Normal sentence
    Indented sentence
another one
1
  • 2
    I got exactly your desire output. Commented Sep 8, 2021 at 10:46

1 Answer 1

3
>>> print(bytes_string.decode("unicode_escape"))
Normal sentence
    Indented sentence
another one
>>>
Sign up to request clarification or add additional context in comments.

Comments

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.