I want to maintain a variable with a string which contains backslashes and don't want to alter that. When I try to use the string, it gets extra backslashes as escape characters. I tried with 'r' ( raw ) modifier - but it didn't help.
Python 2.7.3 (default, Feb 27 2014, 19:58:35)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> s = r'\abc'
>>> s
'\\abc'
I have a test where I am trying to have an array of possible values with ''. But when I take them out, it doesn't come as expected:
>>> value = [r'"\1"', r'"\\1"', r'"\\\1"' ]
>>> for val in value:
... print value
...
['"\\1"', '"\\\\1"', '"\\\\\\1"']
['"\\1"', '"\\\\1"', '"\\\\\\1"']
['"\\1"', '"\\\\1"', '"\\\\\\1"']
How do I do this?
I saw questions regarding the problem with backslash related issues in Python. But I couldn't get a specific answer for the problem that I am hitting.