Andrew Barnert added the comment:
One last thing, a quick & dirty solution that works today, if you don't mind
accessing private internals of stdlib classes, and don't mind giving up the
performance of _io for _pyio, and don't need a solution for binary files:
class MyTextIOWrapper(_pyio.TextIOWrapper):
def readrecord(self, sep):
readnl, self._readnl = self._readnl, sep
try:
return self.readline()
finally:
self._readnl = readnl
Or, if you prefer:
class MyTextIOWrapper(_pyio.TextIOWrapper):
def __init__(self, *args, separator, **kwargs):
super().__init__(*args, **kwargs)
self._readnl = separator
For binary files, there's no solution quite as simple; you need to write your
own readline method by copying and pasting the one from _pyio.RawIOBase, and
the modifications to use an arbitrary separator aren't quite as trivial as they
look at first (at least if you want multi-byte separators).
----------
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue1152248>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com