Is there a function to remove escape characters from a string ?

Jeremiah Dodds jeremiah.dodds at gmail.com
Thu Dec 25 07:35:39 EST 2008


On Thu, Dec 25, 2008 at 7:02 AM, James Stroud <jstroud at mbi.ucla.edu> wrote:

> Stef Mientki wrote:
>
>> hello,
>>
>> Is there a function to remove escape characters from a string ?
>> (preferable all escape characters except "\n").
>>
>> thanks,
>> Stef
>>
>
>
>
import string

test = 'this\r is a test\t yeah\n'

for c in string.printable[-5:]:
     if c != '\n':
        test = test.replace(c, ' ')


Hmm, should the escape codes be in their own little list in string? Or are
they, and I'm just not seeing them? Is string.printable[-5:] a reliable way
to get the list of escape codes?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20081225/269c2566/attachment.html>


More information about the Python-list mailing list