Форум сайта python.su
bwТак в том и дело, что это от платформы зависит. В доке про это явно написано. Как я понял, TC как раз на винде.
У меня нет возможности под виндой проверить, но в линухе этот флажок на “вырезание” \r не влияет. Т.е. ‘r’ вместо ‘rb’ это ни в коем случае не решение обсуждаемой проблемы.
Офлайн
In addition to the standard fopen() values mode may be ‘U’ or ‘rU’. Python is usually built with universal newline support; supplying ‘U’ opens the file as a text file, but lines may be terminated by any of the following: the Unix end-of-line convention ‘\n’, the Macintosh convention ‘\r’, or the Windows convention ‘\r\n’. All of these external representations are seen as ‘\n’ by the Python program. If Python is built without universal newline support a mode with ‘U’ is the same as normal text mode.
>>> open(p, 'rU').read()
'111\n222\n333\n'
>>> open(p, 'rbU').read()
'111\n222\n333\n'
Офлайн