Escaping certain characters
Kent Johnson
kent37 at tds.net
Sat Sep 10 22:10:32 EDT 2005
Jan Danielsson wrote:
> Robert Kern wrote:
> [---]
>
>>>Hmm... On second thought, I need to escape more characters.
>>>
>>>Is there no other way to escape characters in strings?
>>
>>Which characters?
>
>
> I need to escape '\n', '"', '[' and ']'. I finally went with a few of
> these:
> string.replace('\n', '\\n')
> string.replace('"', '\\"')
You might like this recipe:
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81330
Kent
More information about the Python-list
mailing list