Reading a file and resuming reading.
Karim Ali
kakeez at hotmail.com
Fri May 25 11:00:56 EDT 2007
Hrvoje Niksic <hniksic at xemacs.org> wrote:
>If you open the file in binary mode, you can easily keep track of the
>position in file:
>
>bytepos = 0
>with file(filename) as f:
> for line in f:
> ... process line ...
> bytepos += len(line)
>
>If you need to restart the operation, simply seek to the previously
>known position:
>
># restart with old bytyepos
>with file(filename) as f:
> f.seek(bytepos)
> for line in f:
> ... process line ...
> bytepos += len(line)
>--
Thanks! This works perfectly. I did not know you can iterate directly using
the file handle!
Karim
_________________________________________________________________
Windows Live Hotmail, with safety bar colour coding, helps identify
suspicious mail before it takes your daughter out on a date. Upgrade today
for a better look. www.newhotmail.ca?icid=WLHMENCA152
More information about the Python-list
mailing list