I have an iterable of bytes
, such as
bytes_iter = (
b'col_1,',
b'c',
b'ol_2\n1',
b',"val',
b'ue"\n',
)
(but typically this would not be hard coded or available all at once, but supplied from a generator say) and I want to convert this to an iterable of str
lines, where line breaks are unknown up front, but could be any of \r
, \n
or \r\n
. So in this case would be:
lines_iter = (
'col_1,col_2',
'1,"value"',
)
(but again, just as an iterable, not so it's all in memory at once).
How can I do this?
Context: my aim is to then pass the iterable of str lines to csv.reader
(that I think needs whole lines?), but I'm interested in this answer just in general.