Target: Remove '\x' from string.
split(), strip(), and replace() all give the same error.
Can anyone help me out?
my_list = '\x00\x06\x00'
my_list.replace('\x', '')
ValueError: invalid \x escape
Target: Remove '\x' from string.
split(), strip(), and replace() all give the same error.
Can anyone help me out?
my_list = '\x00\x06\x00'
my_list.replace('\x', '')
ValueError: invalid \x escape
 
    
    The default string literal in Python considers backslash as an escape character.
To interpret backslash literally, use r'my string with \x in it', so try:
my_list.replace(r'\x', '')
https://docs.python.org/3/reference/lexical_analysis.html#string-and-bytes-literals
What exactly do "u" and "r" string flags do, and what are raw string literals?
 
    
    You need to put an r before the '\x' in replace()  as well as the string. That will tell python that \ should be interpreted as a character and not as an escape character.
my_list = r'\x00\x06\x00'
my_list.replace(r'\x', '')
