Most direct way to strip unoprintable characters out of a string?

Steve Bergman steve at rueb.com
Sat Sep 24 12:44:40 EDT 2005


When sanitizing data coming in from HTML forms, I'm doing this (lifted 
from the Python Cookbook):

from string import maketrans, translate, printable
allchars = maketrans('','')
delchars = translate(allchars, allchars, printable)
input_string = translate(input_string, allchars, delchars)

Which is OK.  But it seems like there should be more straightforward way 
that I just haven't figured out.  Is there?

Thanks,
Steve Bergman



More information about the Python-list mailing list