Найти - Пользователи
Полная версия: не удается убрать перевод каретки \n
Начало » Python для новичков » не удается убрать перевод каретки \n
1 2
Александр Кошелев
bw
У меня нет возможности под виндой проверить, но в линухе этот флажок на “вырезание” \r не влияет. Т.е. ‘r’ вместо ‘rb’ это ни в коем случае не решение обсуждаемой проблемы.
Так в том и дело, что это от платформы зависит. В доке про это явно написано. Как я понял, TC как раз на винде.
bazooka
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'
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Powered by DjangoBB