Filtering out non-readable characters

Steven D'Aprano steve at REMOVETHIScyber.com.au
Tue Jul 19 16:03:36 CEST 2005


On Tue, 19 Jul 2005 20:28:31 +1200, Ross wrote:

> On 15 Jul 2005 17:33:39 -0700, "MKoool" <mohan at terabolic.com> wrote:
> 
>>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
> 
> Easiest way is open the file with EdXor (freeware editor), select all,
> Format > Wipe Non-Ascii.
> 
> Ok it's not python, but it's the easiest.

1 Open Internet Explorer
2 Go to Google
3 Search for EdXor
4 Browser locks up
5 Force quit with ctrl-alt-del
6 Run anti-virus program
7 Download new virus definitions
8 Remove viruses
9 Run anti-spyware program
10 Download new definitions
11 Remove spyware
12 Open Internet Explorer
13 Download Firefox
14 Install Firefox
15 Open Firefox
16 Go to Google
17 Search for EdXor
18 Download application
19 Run installer
20 Reboot
21 Run EdXor
22 Open file
23 Select all
24 Select Format>Wipe Non-ASCII
25 Select Save
26 Quit EdXor

Hmmm. Perhaps not *quite* the easiest way :-)



-- 
Steven.




More information about the Python-list mailing list