[Python-ideas] os.path.isbinary

MRAB python at mrabarnett.plus.com
Thu Aug 1 20:47:22 CEST 2013


On 01/08/2013 19:29, David Mertz wrote:
> On Wed, Jul 31, 2013 at 5:42 PM, Chris Angelico <rosuav at gmail.com
> <mailto:rosuav at gmail.com>> wrote:
>
>     This sounds more like a job for a file-like object, maybe a subclass
>     of file that reads (and buffers) the first 512 bytes, guesses whether
>     it's text or binary, and then watches everything that goes through
>     after that and revises its guess later on.
>
>
> Something like:
>
>    if fh.read(512).isprintable():
>        do_the_ascii_stuff(fh)
>    else:
>        do_the_bin_stuff(fh)
>
Except that:

 >>> "\n".isprintable()
False



More information about the Python-ideas mailing list