Search code examples
pythonstringunicodeencode

How can I print the raw unicode in python?


I am novice in Python, so maybe I can't express it well...

I got a string '\xb9\xfe'

I want it print in this very fashion '\xb9\xfe', not converting to a Chinese character '哈'.

What is the proper way to do it?


Solution

  • Use a raw string literal instead:

    r'\xb9\xfe'
    

    or print the output of repr() of your string:

    print(repr('\xb9\xfe'))