A recent question about splitting a binary file using null characters made me think of a similar text-oriented question.
Given the following file:
Parse me using spaces, please.
Using Raku, I can parse this file using space (or any chosen character) as the input newline character, thus:
my $fh = open('spaced.txt', nl-in => ' ');
while $fh.get -> $line {
put $line;
}
Or more concisely:
.put for 'spaced.txt'.IO.lines(nl-in => ' ');
Either of which gives the following result:
Parse me using spaces, please.
Is there something equivalent in Python 3?
The closest I could find required reading an entire file into memory:
for line in f.read().split('\0'):
print line
Update: I found several other older questions and answers that seemed to indicate that this isn't available, but I figured there may have been new developments in this area in the last several years:
Python restrict newline characters for readlines()
Change newline character .readline() seeks