Escaping the semicolon?

Jerry Hill malaclypse2 at gmail.com
Tue Dec 4 11:45:21 EST 2007


On Dec 4, 2007 11:33 AM, Nick <nickjbyrne at gmail.com> wrote:
> Try "123 *?/ abc d;o /$'" as the argument... and you get -
>
> 123 \*\?\/ abc d\\;o \/\$

That's because of the order you're doing the replacement.  Put a print
statement inside your for loop and you'll see something like this:

input starts as "123 *?/ abc d;o /$'"
Then when you replace ';' with '\;' you get input = "123 *?/ abc d\;o /$'"
Then the next replacement replaces '\' with '\\' so you get input =
"123 *?/ abc d\\;o /$'"

If you move '\\' to the front of your list of replacement characters,
things will probably work as you expect.

-- 
Jerry



More information about the Python-list mailing list