Need to know if a file as only ASCII charaters
MRAB
python at mrabarnett.plus.com
Tue Jun 16 14:35:49 EDT 2009
norseman wrote:
> Scott David Daniels wrote:
>> Dave Angel wrote:
>>> Jorge wrote:
>>>> Hi there,
>>>> I'm making a application that reads 3 party generated ASCII files,
>>>> but some
>>>> times
>>>> the files are corrupted totally or partiality and I need to know if
>>>> it's a
>>>> ASCII file with *nix line terminators.
>>>> In linux I can run the file command but the applications should run in
>>>> windows.
>
> you are looking for a \x0D (the Carriage Return) \x0A (the Line feed)
> combination. If present you have Microsoft compatibility. If not you
> don't. If you think High Bits might be part of the corruption, filter
> each byte with byte && \x7F (byte AND'ed with hex 7F or 127 base 10)
> then check for the \x0D \x0A combination.
> Run the test on a known text setup. Intel uses one order and the SUN and
> the internet another. The BIG/Little ending confuses many. Intel
> reverses the order of multibyte numerics. Thus - Small machine has big
> ego or largest byte value last. Big Ending. Big machine has small ego.
> Little Ending. Some coders get the 0D0A backwards, some don't. You
> might want to test both.
>
In an ASCII file endianness is irrelevant.
More information about the Python-list
mailing list