In Python, f.readline() returns the next line from the file f . That is, it starts at the current position f , reads until it encounters a line break, returns everything in between and updates the position f .
Now I want to do the same thing, but for space-separated files (and not just newlines). For example, consider a file f with the contents
token1 token2 token3 token4 token5
So I'm looking for some readtoken() function, so after opening f first call to f.readtoken() returns token1 , the second call reconfigures token2 , etc.
For efficiency and to avoid problems with very long lines or very large files, buffering should not be.
I was pretty sure that this should be possible out of the box with the standard library. However, I did not find a suitable function or way to override the delimiters for readline() .
source share