Title: export the set newline value on TextIOBase/TextIOWrapper
Type: enhancement Stage:
Components: IO Versions:
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: benjamin.peterson, calestyo
Priority: normal Keywords:

Created on 2021-02-27 05:45 by calestyo, last changed 2021-03-05 21:03 by terry.reedy.

Messages (1)
msg387767 - (view) Author: Christoph Anton Mitterer (calestyo) Date: 2021-02-27 05:45

It seems there is no way to determine the newline value (None, '', \n, \r, \r\n) of a given text stream.
.newlines rather gives the newlines that have been encountered so far.

Just like .encoding and .errors this would be quite useful for anything that gets a stream and operates on it, possibly needing to know which newlines it will see when reading from the stream.

One example would be, after line = stream.readline(4096+n) one want's to know whether actually a full line of 4096 characters has been read.
Putting aside newline="", for simplicity here, n already depends on whether newline was None, \n, \r or \r\n, as would any check like line.endswith(foo).

Maybe some attribute, that indicates the most recently read newline in newline="" mode, would be helpful, too.

Date User Action Args
2021-03-05 21:03:13terry.reedysetnosy: + benjamin.peterson
2021-02-27 05:45:28calestyocreate