I am looking for a way to prefix strings in python with a single backslash, e.g. "]" -> "]". Since "\" is not a valid string in python, the simple
mystring = '\' + mystring
won't work. What I am currently doing is something like this:
mystring = r'\@@@' + mystring
mystring.replace('@@@','')
While this works most of the time, it is not elegant and also can cause problems for strings containing "@@@" or whatever the "filler" is set to. Is there a bette way of doing this?
mystring = '\\' + mystring-- you must "escape" literal backslash characters in a string with another backslash.