test if a file or string is text or binary

Category: Python - Miscellaneous

Here's a quick test to see if a file or string contains text or is binary. The difference between text and binary is ill-defined, so this duplicates the definition used by Perl's -T flag, which is:
<br/>
The first block or so of the file is examined for odd characters such as strange control codes or characters with the high bit set. If too many strange characters (>30%) are found, it's a -B file, otherwise it's a -T file. Also, any file containing null in the first block is considered a binary file. Date: 11 February, 2012


Files

Homepage: http://code.activestate.com/recipes/173220-test-if-a-file-or-string-is-text-or-binary/?in=lang-python

Developer: Andrew Dalke

License: Python License

Operating System: Windows

Add a Comment

all are required fields

     
What do you think of this resource?

Select Your Rate:

Votes:0

 

Related Scripts Download

ANDREW's Not a DVD Ripping and Encoding Wizard, but an interactive wrapper or a Bash script that uses oggenc, mencoder and mkv/ogmmerge to create, from a DVD, Matroska or Ogg Media files containing an ISO MPEG-4 compliant video track, encoded using FFmpeg libavcodec or XviD codec, one or more AC-3 or Vorbis audio tracks and a chapters index.

developer Developer: Alessandro Di Rubbo
license License: GNU General Public License (GPL)
operating systems Operating System: Platform Independent


dhtmlxVault is a DHTML file upload component that helps to implement modern and feature-rich file uploading part of a web application.

developer Developer: Ivan Petrenko
license License: GNU General Public License (GPL)
operating systems Operating System: Cross-Platform


Provider of data recovery software offers file rescue solution to retrieve lost, missed data from damaged storage media.

developer Developer: Data Recovery Reviews
license License: GNU General Public License (GPL)
operating systems Operating System: Not Available


Deal with file recovery program for recovering deleted pictures, images, recordings from zune media player.

developer Developer: file recovery
license License: GNU General Public License (GPL)
operating systems Operating System: Not Available


Downloads available for file recovery tools that provide solutions for almost any data lost situation covering a variety of storage devices.

developer Developer: windows vista file recovery
license License: GNU General Public License (GPL)
operating systems Operating System: Not Available


Company provides data recovery software to restores data lost due to virus attack, system malfunctioning or disk formatting.

developer Developer: Data recovery software
license License: GNU General Public License (GPL)
operating systems Operating System: Not Available


We offer services of memory card repair software to recover corrupted pictures, video files from inaccessible picture card.

developer Developer: Card recovery
license License: GNU General Public License (GPL)
operating systems Operating System: Not Available


Description: Rock, Scissors, Paper Game.

developer Developer: yaipa haa
license License: Python License
operating systems Operating System: Windows


This is an industry standard algorithm I ported to python.

developer Developer: David Shaw
license License: Python License
operating systems Operating System: Windows