large dictionary creation takes a LOT of time.
Caleb Hattingh
caleb1 at telkomsa.net
Fri Apr 29 15:37:48 EDT 2005
In fact, as one of the Peter's (either Otten or Hansen) explained to me,
for line in open(file):
is actually both faster (being buffered) and generally better for very
large files because it doesn't read the whole file into memory, like
readlines does (if you have a memory limitation).
On Fri, 29 Apr 2005 12:00:37 -0400, Kent Johnson <kent37 at tds.net> wrote:
> Maksim Kasimov wrote:
>> Kent Johnson wrote:
>> > for line in open(path):
>> the line of your example raise another question: opened file will be
>> read at once time, as method readlines() do, or it will be read line by
>> line as method readline() do.
>
> It will be read line by line as readline() does.
>
>> as far i know, it is depends on implementation of method "__iter__" of
>> the object that "open()" returns, so another question: where i can find
>> such an information (about how does such a functions works)?
>
> http://docs.python.org/lib/built-in-funcs.html
> http://docs.python.org/lib/bltin-file-objects.html
>
> Kent
More information about the Python-list
mailing list