[Tutor] Questions on file.read
Kent Johnson
kent37 at tds.net
Thu Jul 14 15:47:44 CEST 2005
Max Noel wrote:
> In any cas, you should try to avoid using file.read without a size
> parameter. If you're processing text files, reading them one line at a
> time would be a good start (for line in open ('filename.txt'): is an
> instance of Best Thing Ever).
Yes, this is good advice, if you can process the file line-by-line that is the best way to do it. If you know you have to handle whole files that won't fit in memory you might want to use the mmap module.
Kent
More information about the Tutor
mailing list