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

James Stroud jstroud at mbi.ucla.edu
Thu Dec 25 13:02:02 CET 2008


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

WANTED = string.printable[:-5] + "\n"

def descape(s, w=WANTED):
   return "".join(c for c in s if c in w)


James


-- 
James Stroud
UCLA-DOE Institute for Genomics and Proteomics
Box 951570
Los Angeles, CA  90095

http://www.jamesstroud.com



More information about the Python-list mailing list