[issue3359] add 'rbU' mode to open()
anatoly techtonik [EMAIL PROTECTED] added the comment: This '\r' makes things worse. I am also on Windows and didn't thought that rb processes '\r\n' linefeeds as a side-effect of '\n' being the last character. Thanks. newline='' is just what I need. I guess there is no alternative to it in 2.5 series except splitting lines returned from binary read manually. What about file.newlines attribute - is it preserved in 2.6/Py3k? BTW, it would be nice to have this example in manual. ___ Python tracker [EMAIL PROTECTED] http://bugs.python.org/issue3359 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue3359] add 'rbU' mode to open()
Amaury Forgeot d'Arc [EMAIL PROTECTED] added the comment: Please read http://docs.python.org/dev/library/io.html#io.TextIOBase.newlines ___ Python tracker [EMAIL PROTECTED] http://bugs.python.org/issue3359 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue3359] add 'rbU' mode to open()
Skip Montanaro [EMAIL PROTECTED] added the comment: As I indicated in msg69679 if you want to see the line endings just open the file in binary mode ('rb'). ___ Python tracker [EMAIL PROTECTED] http://bugs.python.org/issue3359 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue3359] add 'rbU' mode to open()
anatoly techtonik [EMAIL PROTECTED] added the comment: If lineends are mixed I would like to leave them as is. ___ Python tracker [EMAIL PROTECTED] http://bugs.python.org/issue3359 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue3359] add 'rbU' mode to open()
Amaury Forgeot d'Arc [EMAIL PROTECTED] added the comment: Did you look at the io.open() function? It's a new module in python2.6, but also the builtin open in py3k! * On input, if newline is None, universal newlines mode is enabled. Lines in the input can end in '\n', '\r', or '\r\n', and these are translated into '\n' before being returned to the caller. If it is '', universal newline mode is enabled, but line endings are returned to the caller untranslated. If it has any of the other legal values, input lines are only terminated by the given string, and the line ending is returned to the caller untranslated. I suggest to try io.open(filename, newline=) -- nosy: +amaury.forgeotdarc ___ Python tracker [EMAIL PROTECTED] http://bugs.python.org/issue3359 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue3359] add 'rbU' mode to open()
anatoly techtonik [EMAIL PROTECTED] added the comment: That's fine with me. I just need a 'rbU' mode to know in which format should I write the output file if I want to preserve proper line endings regardless of platform. As for Python 2.6 note - I would replace may convert with converts. ___ Python tracker [EMAIL PROTECTED] http://bugs.python.org/issue3359 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue3359] add 'rbU' mode to open()
Georg Brandl [EMAIL PROTECTED] added the comment: If you want to write your own line endings, read with rU and write with rb. ___ Python tracker [EMAIL PROTECTED] http://bugs.python.org/issue3359 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue3359] add 'rbU' mode to open()
Georg Brandl [EMAIL PROTECTED] added the comment: At least the 2.6 docs say The default is to use text mode, which may convert ``'\n'`` characters to a platform-specific representation on writing and back on reading. ___ Python tracker [EMAIL PROTECTED] http://bugs.python.org/issue3359 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue3359] add 'rbU' mode to open()
anatoly techtonik [EMAIL PROTECTED] added the comment: This behavior is inherited from the C-level fopen() and therefore normal text mode is whatever that defines. Is this really nowhere documented? Relation to fopen() function may be documented, but there is no explanation of what normal text mode is. Is it really pythonic that a script writer without former experience with C, stdio and fopen should be aware of inherited fopen behavior when programming Python? ___ Python tracker [EMAIL PROTECTED] http://bugs.python.org/issue3359 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue3359] add 'rbU' mode to open()
Georg Brandl [EMAIL PROTECTED] added the comment: This behavior is inherited from the C-level fopen() and therefore normal text mode is whatever that defines. Is this really nowhere documented? ___ Python tracker [EMAIL PROTECTED] http://bugs.python.org/issue3359 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue3359] add 'rbU' mode to open()
Skip Montanaro [EMAIL PROTECTED] added the comment: anatoly If you open file with 'r' - all line endings will be mapped anatoly precisely to '\n' anyways, so it has nothing to do with 'U' anatoly mode. Before 3.0 at least, if you copy a text file from, say, Windows to Mac, and open it with 'r', you get lines which end in '\r\n'. Here's a simple example: open(dos.txt, rb).read() 'a single line\r\nanother line\r\n' f = open(dos.txt) f.next() 'a single line\r\n' f = open(dos.txt, r) f.next() 'a single line\r\n' f.next() 'another line\r\n' If, on the other hand, you open it with 'rU', the '\r\n' literal line ending is converted, even though CRLF is not the canonical Mac line ending: f = open(dos.txt, rU) f.next() 'a single line\n' f.next() 'another line\n' Skip ___ Python tracker [EMAIL PROTECTED] http://bugs.python.org/issue3359 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue3359] add 'rbU' mode to open()
Skip Montanaro [EMAIL PROTECTED] added the comment: The whole idea of universal newline mode is that the various possible line endings ('\r', '\n' and '\r\n') are all mapped to '\n' precisely so the user doesn't have to detect and fiddle with them. Using 'b' and 'U' together makes no sense. * If you really want to see the line endings use 'rb'. * If you don't care about the line endings regardless of source, use 'rU'. * Otherwise use 'r'. -- nosy: +skip.montanaro resolution: - invalid status: open - closed ___ Python tracker [EMAIL PROTECTED] http://bugs.python.org/issue3359 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue3359] add 'rbU' mode to open()
anatoly techtonik [EMAIL PROTECTED] added the comment: If you open file with 'r' - all line endings will be mapped precisely to '\n' anyways, so it has nothing to do with 'U' mode. ___ Python tracker [EMAIL PROTECTED] http://bugs.python.org/issue3359 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue3359] add 'rbU' mode to open()
Georg Brandl [EMAIL PROTECTED] added the comment: If you open file with 'r' - all line endings will be mapped precisely to '\n' anyways, so it has nothing to do with 'U' mode. No they won't -- only the platform-specific newline will. On Unix, 'r' and 'rb' are the same. -- nosy: +georg.brandl ___ Python tracker [EMAIL PROTECTED] http://bugs.python.org/issue3359 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue3359] add 'rbU' mode to open()
New submission from anatoly techtonik [EMAIL PROTECTED]: 'rU' universal newline support is useless, because read lines end with '\n' regardless of actual line end in the source file. Applications that care about line ends still open file in binary mode and gather the stats manually. So, to make this mode useful - the 'rbU' should be addded. Otherwise it doesn't worth complication both in C code and in documentation. -- components: Library (Lib) messages: 69673 nosy: techtonik severity: normal status: open title: add 'rbU' mode to open() versions: Python 2.6, Python 3.0 ___ Python tracker [EMAIL PROTECTED] http://bugs.python.org/issue3359 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com