Re: Bug#722156: ITP: binaryornot -- Ultra-lightweight pure Python package to check if a file is binary or text.
On 08.09.2013 16:40, Vincent Bernat wrote:
> Package: wnpp
> Severity: wishlist
> Owner: Vincent Bernat <email@example.com>
> * Package name : binaryornot
> Version : 0.1.1
> Upstream Author : Audrey Roy <firstname.lastname@example.org>
> * URL : https://github.com/audreyr/binaryornot
> * License : BSD
> Programming Lang: Python
> Description : Ultra-lightweight pure Python package to check if a file is binary or text.
> This Python package provides a function to check if a file is a text
> file or a binary file. It uses the same heuristic as file(1) by
> looking at the first 1024 bytes of the file and checks that all
> characters are printable.
do we need a package for that?
it is effectively:
with open(filename, 'r') as f:
chunk = f.read(1024)
textchars = ''.join(map(chr, [7,8,9,10,12,13,27] + range(0x20,
and only works with utf-8 or ascii encoded files.