I need to read a file with some strange string lines like : \x72\xFE\x20TEST_STRING\0\0\0
but when I do a print of this string (with repr()) it prints this : r\xfe TEST_STRING\x00\x00\x00
Example :
>>> test = '\x72\xFE\x20TEST_STRING\0\0\0'
>>> print test
r? TEST_STRING
>>> print repr(test)
'r\xfe TEST_STRING\x00\x00\x00'
How can I get the same line from a file in Python and my editor ? Is python changing encoding during string manipulation ?
print sdiffers from the output ofprint repr(s)?'\x72'in a string literal does not mean "a backslash, the letter x, the digit 7 and the digit 2"; it means "the byte whose value is written as '72' in hexadecimal, i.e. 114, which happens to be the letter r".