Finding nonprintable characters?

Gerhard =?unknown-8bit?Q?H=E4ring?= gh_pythonlist at gmx.de
Tue Feb 19 14:41:49 EST 2002


Le 19/02/02 ? 12:14, VanL écrivit:
> Hello,
> 
> I have a function
> 
> isBinary(filehandle)
> 
> that I'm not sure how to implement.  I've decided to define binary as 
> containing characters above \x80.

This algorithm only works for ASCII text. German, Spanish, French and
other texts are right out.

If you're on Unix, I'd suggest you interface the file command instead.

> But  what is the best way to do this?
> 
> 1. iterate through xreadline, so the whole thing doesn't get loaded into 
> memory?

You can read chunks of data with the read method of file-like objects.
read() takes an optional parameter with the lenght of the block. So
.read(1024) will read chunks of a lenght of 1024 bytes, for example.

Gerhard
-- 
This sig powered by Python!
Außentemperatur in München: 4.0 °C      Wind: 6.8 m/s




More information about the Python-list mailing list