It could be faster if you open the file before the for loop, since it is the same file used at each iteration.