Python Reverse Reversal Function

if I have a string with characters ( 0x61 0x62 0xD ), the repr function of this string will return 'ab\r' .

Is there a way to do the opposite operation: if I have the string 'ab\r' (with characters 0x61 0x62 0x5C 0x72 ), I need to get the string 0x61 0x62 0xD .

+8
python repr
source share
1 answer

I think you are looking for ast.literal_eval :

 >>> s = repr("ab\r") >>> s "'ab\\r'" >>> from ast import literal_eval >>> literal_eval(s) 'ab\r' 
+16
source share

All Articles