-1

I want to search and replace the string "\" from the array 'abc' in python code.

I'm using the following code

abc=re.sub("\"," ",abc)

But it is giving the following error

   File "script", line 99
    line_map=re.sub("\"," ",line_map)
                                    ^
SyntaxError: EOL while scanning string literal**

What changes should I make to the code?

tripleee
  • 175,061
  • 34
  • 275
  • 318
Vysakh K
  • 21
  • 1
  • 3

1 Answers1

0

You could try replacing the "\" with "\\" in general "\" is used as escape character, thus to get the actual one being used, you need to use it two times.

Dr.Jukka
  • 2,346
  • 2
  • 15
  • 20
  • Hey thank you for the immediate help. But that is not helping me. It is giving me the following error Traceback (most recent call last): File "script", line 99, in line_map=re.sub("\\"," ",line_map) File "/grid/common/pkgs/python/latest/lib/python2.6/re.py", line 151, in sub return _compile(pattern, 0).sub(repl, string, count) File "/grid/common/pkgs/python/latest/lib/python2.6/re.py", line 245, in _compile raise error, v # invalid expression sre_constants.error: bogus escape (end of line) – Vysakh K Apr 13 '14 at 12:17
  • Hey it worked! I used the following code abc=abc.replace("\\","") – Vysakh K Apr 13 '14 at 12:35