Detecting line endings

Arthur ajsiegel at optonline.com
Tue Feb 7 06:59:48 EST 2006


Alex Martelli wrote:
> Fuzzyman <fuzzyman at gmail.com> wrote:
> 
> 
>>Hello all,
>>
>>I'm trying to detect line endings used in text files. I *might* be
>>decoding the files into unicode first (which may be encoded using
> 
> 
> Open the file with 'rU' mode, and check the file object's newline
> attribute.

Do you think it would be sensible to have file.readline in universal 
newline support by default?

I just got flummoxed by this issue, working with a (pre-alpha) package 
by very experienced Python programmers who sent file.readline to 
tokenizer.py without universal newline support.  Went on a long (and 
educational) journey trying to figure out why my file was not being 
processed as expected.

Are there circumstances that it would be sensible to have tokenizer 
process files without universal newline support?

The result here was having tokenizer detect indentation inconstancies 
that did not exist - in the sense that the files were compiled and ran 
fine by Python.exe.

Art



More information about the Python-list mailing list