Detecting line endings
Fuzzyman
fuzzyman at gmail.com
Wed Feb 8 04:00:03 EST 2006
Alex Martelli wrote:
> Fuzzyman <fuzzyman at gmail.com> wrote:
> ...
> > I can't open with a codec unless an encoding is explicitly supplied. I
> > still want to detect UTF16 even if the encoding isn't specified.
> >
> > As I said, I ought to test this... Without metadata I wonder how Python
> > determines it ?
>
> It doesn't. Python doesn't even try to guess: nor would any other
> sensible programming language.
>
Right, so opening in "rU" mode and testing the 'newline' attribute
*won't* work for UTF16 encoded files. (Which was what I was asking.)
I'll have to read, determine encoding, decode, then *either* use my
code to determine line endings *or* use ``splitlines(True)``.
All the best,
Fuzzyman
http://www.voidspace.org.uk/python/index.shtml
>
> Alex
More information about the Python-list
mailing list