Re: Filtering out non-readable characters
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.python archive

Re: Filtering out non-readable characters

From: Adriaan Renting <renting@astron.nl>
Date: Fri Jul 29 2005 - 11:42:25 CEST

def StripNoPrint(self, S):
        from string import printable
        return "".join([ ch for ch in S if ch in printable ])

Adriaan Renting | Email: renting@astron.nl
ASTRON | Phone: +31 521 595 217
P.O. Box 2 | GSM: +31 6 24 25 17 28
NL-7990 AA Dwingeloo | FAX: +31 521 597 332
The Netherlands | Web: http://www.astron.nl/~renting/
>>> "MKoool" <mohan@terabolic.com> 07/16/05 2:33 AM >>>
I have a file with binary and ascii characters in it. I massage the
data and convert it to a more readable format, however it still comes
up with some binary characters mixed in. I'd like to write something
to just replace all non-printable characters with '' (I want to delete
non-printable characters).

I am having trouble figuring out an easy python way to do this... is
the easiest way to just write some regular expression that does
something like replace [^\p] with ''?

Or is it better to go through every character and do ord(character),
check the ascii values?

What's the easiest way to do something like this?

thanks

-- 
http://mail.python.org/mailman/listinfo/python-list
Received on Thu Sep 29 17:13:47 2005