Re-open files in Python?

You can reset the file pointer by calling seek():

file.seek(0)

will do it. You need that line after your first readlines(). Note that file has to support random access for the above to work.

Leave a Comment