bharal
bharal

Reputation: 16164

str.replace function with parentheses

I don't know how to use the "replace" python string function to remove brackets.

i assume i'm doing something wrong here - i have this code:

line = line.replace('\(','A')

which, when faced with a string that has a ( in it doesn't do anything. I've also tried

line = line.replace('\\(','A')

but no dice there either.

I know that the function works - (this is for converting sqlite data dump to mysql and seriously why hasn't someone made a $10 app to do this? I would have bought it by now.) - because i can do

line = line.replace('CREATE','A')

and i get all the create statements replaced by the letter A...

What am i missing here?

Upvotes: 5

Views: 12206

Answers (1)

Eric
Eric

Reputation: 97571

Don't escape it?

line = line.replace('(', 'A')

str.replace doesn't use regular expressions. That's what the re.sub function does.

Upvotes: 8

Related Questions