iostream-like lib?
Anton Muhin
antonmuhin at sendmail.ru
Thu May 15 14:34:11 EDT 2003
Max Khesin wrote:
> The trouble is that readline() reads more than i have to in the first place,
> even before I call split().
> I did hack it along the lines you suggested with a generator (limiting
> readline() to a number of bytes and accounting for the last character being
> possibly whitespace). I was just wondering if (and why not) there is/is not
> direct support for whitespace-delimited input.
I don't know :)
The only thig I want to add: I see no reason why you should limit
readline with number of bytes? Doesn't the following code (untested) work?
def read_tokens(filename):
f = file(filename)
for l in f:
for token in l.split():
yield token
close(f)
Best regards,
anton.
More information about the Python-list
mailing list