easy way to remove nonprintable chars from string
sismex01 at hebmex.com
sismex01 at hebmex.com
Thu Jul 24 16:11:46 EDT 2003
> From: Isaac Raway [mailto:isaac at blueapples.org]
> Sent: Jueves, 24 de Julio de 2003 03:04 p.m.
>
> This seems to work. Not sure how fast it'd be, though.
>
> def stripNoPrint(str):
> results = ""
> for char in str:
> if string.printable.find(char):
> results += char
> return results
>
And to make this thread end quickly, the functional version
of the above would be like:
def StripNoPrint(S):
from string import printable
return "".join(filter(lambda ch:ch in printable, S))
And converted to use list comprehensions:
def StripNoPrint(S):
from string import printable
return "".join([ ch for ch in S if ch in printable ])
HTH!!!
-gustavo
Advertencia:La informacion contenida en este mensaje es confidencial y
restringida, por lo tanto esta destinada unicamente para el uso de la
persona arriba indicada, se le notifica que esta prohibida la difusion de
este mensaje. Si ha recibido este mensaje por error, o si hay problemas en
la transmision, favor de comunicarse con el remitente. Gracias.
More information about the Python-list
mailing list