classification
Title: document whether io.TextIOBase.readline(size>0) will always read the full newline
Type: Stage:
Components: Documentation Versions:
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: docs@python Nosy List: benjamin.peterson, calestyo, docs@python
Priority: normal Keywords:

Created on 2021-02-27 02:15 by calestyo, last changed 2021-03-17 16:20 by calestyo.

Messages (3)
msg387758 - (view) Author: Christoph Anton Mitterer (calestyo) Date: 2021-02-27 02:15
Hey.

It would be nice if the following behaviour could be definitely clarified:

When reading from a text stream with readline(size) with a n > 0size it says: "If size is specified, at most size characters will be read."

Also, depending on the settings of newlines of the stream, \r\n would be converted to \n.


It's not definitely clear whether a string like
"abc\r\n"
read with a size of = 4 will return "abc\n" (which it seems to do, in other words, it reads actually 5 characters, but sill returns only 4), or whether it returns "abc\r".


Cheers,
Chris.
msg387759 - (view) Author: Christoph Anton Mitterer (calestyo) Date: 2021-02-27 02:16
"a n > 0size" should have read "a size > 0"
msg388935 - (view) Author: Christoph Anton Mitterer (calestyo) Date: 2021-03-17 16:20
I guess that the translation from CRLF to LF simply happens before the size restriction is enforced (which is good so, btw), so effectively it:

will not *read* at most size characters from the stream, but *return* at most size characters from it (with any newlines translated before, and thus more characters read from the stream than returned)
History
Date User Action Args
2021-03-17 16:20:32calestyosetmessages: + msg388935
2021-03-05 21:02:21terry.reedysetnosy: + benjamin.peterson
2021-02-27 02:16:17calestyosetmessages: + msg387759
2021-02-27 02:15:37calestyocreate