in reply to Tip on better performance: Open and close output file or leave it open?

We don't really know enough about your code to give a definitive answer. I think it's pretty obvious that opening and closing a file each time you write to it will take more CPU cycles than keeping it open the whole time. However, there are cases where you might have to close and re-open a file, for example if other processes are accessing the same file during the run of the script. Please see How do I post a question effectively?

It also helps to profile your code to check where the bottlenecks really are.

  • Comment on Re: Tip on better performance: Open and close output file or leave it open?