Determine file type (binary or text)

Peter Hansen peter at
Thu Aug 14 17:15:13 CEST 2003

"David C. Fox" wrote:
> Sami Viitanen wrote:
> > Thanks for the answers.
> >
> > To be more specific I'm making a script that should
> > identify binary files as binary and text files as text.
> >
> > The script is for automating CVS commands and
> > with CVS you have to add the -kb flag to
> > add (or import) binary files. (because it can't itself
> > determine what type the file is). If binary file is not
> > added with -kb the results are awful.
> >
> You should note that the question of when to use -kb is not simply based
> on the contents of the file, but on whether you want CVS/RCS to try to
> merge conflicting versions.
> For example, I recently added some files containing pickled objects
> (used as test data sets for a regression test) to the CVS repository for
> my project.  Although the pickle files are in fact all printable text, a
> CVS/RCS merge of two valid pickle files won't yield a valid pickle file.
>   Therefore, I used -kb to ensure that the developer would always be
> forced to choose a version in the event of a version conflict.

Exactly.  We had the same issue with the project files for the Codewright
text editor.  They are sort of like Windows .INI files, but merging such
files leads to complete disaster, including inability to run Codewright
until the files are manually fixed or removed!


More information about the Python-list mailing list