Re: reading in text files
Re: reading in text files
- Subject: Re: reading in text files
- From: Bob Savage <email@hidden>
- Date: Fri, 01 Feb 2002 14:41:02 -0600
on 2/1/02 1:57 PM, Ondra Cada wrote:
>
>
It *is* nice. RTFM NSFileHandle.html.
Hi, Ondra,
thanks for the pointer, I was thinking about the features for reading a line
at a time, though:
>
f = open("foo.txt") # f is a file object
>
line = f.readline() # line is now a string
>
while line:
>
# do whatever you want with one line,
>
# e.g. string splitting, etc.
>
#
>
line = f.readline()
>
f.close()
I don't see a way to do this with an NSFileHandle, although I agree that it
would be unnecessary to re-implement the binary file features since they are
in NSFileHandle already. I shouldn't have continued to ramble about what
happens when there are no newline characters, as it just made it less
obvious what I was trying to say.
Perhaps NSFileHandle can be extended with a method -readDataToEndOfLine to
match -readDataToEndOfFile? This would make the answer to the original
question something like "Place a category on NSFileHandle which includes
-(NSString *)readDataToEndOfLine; -- then split the string using the
standard NSString methods."
Maybe Apple's idea is that people who need to parse big text files can use
scripting languages, or will just implement this themselves. I still think
it *would* be nice if it were added to the Foundation framework. :)
best,
Bob