detecting newline character
danger at rulez.sk
Sun Apr 24 11:49:46 CEST 2011
On 24.4.2011 11:19, Thomas 'PointedEars' Lahn wrote:
> It is clear now that codecs.open() would not support universal newlines from
> at least Python 2.6 forward as it is *documented* that it opens files in
> *binary mode* only. The source code that I have posted shows that it
> therefore actively removes 'U' from the mode string when the `encoding'
> argument was passed, and always appends 'b' to the mode if not present. As
> a result, __builtin__.open() is called without 'U' in the `mode' argument,
> which is *documented* to set file.newlines to None (regardless whether
> Python was compiled with universal newline support).
OK, it makes much more sense now, thanks for explanation. I didn't
understood it when reading the docs. The io module seems to be good
choice for my use case so I switched to using that for now.
What is still a little confusing for me is that you stated "WFM", which
I interpreted as "Works For Me", in one of your previous replies for
both with and without encoding specified.
I also have to state that it must have been changed sometime during 2.6
line, because I started developing pysublib ca. 20 months ago on python
2.6 (don't know the minor version) and I am quite sure my tests were
passing back in that time...
> The bug, if any, is that codecs.open() does not check for your wrong `mode'
> argument, while io.open() does.
yup, seems like it would be a good idea to sanitize this.
> ¹ RTSL: Read the Source, Luke!
/me makes a note what this means :)
Thank you for your help it's very appreciated.
S pozdravom / Best regards
More information about the Python-list