Basic file operation questions
Jeff Shannon
jeff at ccvcorp.com
Thu Feb 3 16:13:17 EST 2005
Caleb Hattingh wrote:
> Peter
>
>> Yes, you can even write
>>
>> f = open("data.txt")
>> for line in f:
>> # do stuff with line
>> f.close()
>>
>> This has the additional benefit of not slurping in the entire file at
>> once.
>
> Is there disk access on every iteration? I'm guessing yes? It
> shouldn't be an issue in the vast majority of cases, but I'm naturally
> curious :)
Disk access should be buffered, possibly both at the C-runtime level
and at the file-iterator level (though I couldn't swear to that). I'm
sure that the C-level buffering happens, though.
Jeff Shannon
Technician/Programmer
Credit International
More information about the Python-list
mailing list